2017-03-02 2 views
0

%가 낮은 값을 가진 클래스가 하나있는 도넛 형 차트가 있습니다. 도넛 차트에서이 레이블을 숨기고 싶습니다. 이 방법으로, 기본 음모로, 나는 그들이 지저분하다고 생각합니다.도넛 차트에서 낮은 비율 Hidding

내 코드 : 우리는 데이터 속성 "textposition"를 추가 할 수 있습니다

from plotly.offline import init_notebook_mode, iplot 
init_notebook_mode() 
#Dados (values) 
dado_app_nascente = groupped_app_veg.loc[groupped_app_veg["app"] == "Entorno nascente", "area_ha"] 
dado_app_rio = groupped_app_veg.loc[groupped_app_veg["app"] == "Margem de curso d'água", "area_ha"] 

#Legenda ("labels") 
label_app_nascente = groupped_app_veg.loc[groupped_app_veg["app"] == "Entorno Nascente", "class_name"].str.title() 
label_app_rio = groupped_app_veg.loc[groupped_app_veg["app"] == "Margem de curso d'água", "class_name"].str.title() 

#Cores ("marker": {"color"}) 
c_app_nascente = list(groupped_app_veg.loc[groupped_app_veg["app"] == "Entorno nascente", "color"]) 
c_app_rio = list(groupped_app_veg.loc[groupped_app_veg["app"] == "Margem de curso d'água", "color"]) 

fig = { 
    "data": [ 
    { 
     "values": dado_app_nascente, 
     "labels": label_app_nascente, 
     "domain": {"x": [0, .48]}, 
     "name": "area_entorno_nascente", 
     #"hoverinfo":"label+percent+name", 
     "textposition":"inside", 
     "hole": .4, 
     "type": "pie", 
     "marker": {'colors': c_app_nascente}, 
     "showlegend": False 
    },  
    { 
     "values":dado_app_rio, 
     "labels": label_app_rio, 
     "textposition":"inside", 
     "domain": {"x": [.52, 1]}, 
     "name": "area_margem_rio", 
     #"hoverinfo":"label+percent+name", 
     "hole": .4, 
     "type": "pie", 
     "marker": {'colors': c_app_rio}, 

    }], 
    "layout": { 
     "title":"PROPORÇÃO DE CLASSES: VEGETAÇÃO/USO DO SOLO", 
     "width": 1000, 
     "height": 500, 
     "annotations": [ 
      { 
       "font": { 
        "size": 18 
       }, 
       "showarrow": False, 
       "text": "NASCENTE", 
       "x": 0.175, 
       "y": 0.5 
      }, 
      { 
       "font": { 
        "size": 18 
       }, 
       "showarrow": False, 
       "text": "RIO", 
       "x": 0.785, 
       "y": 0.5 
      }, 
      { 
       "font": { 
        "size": 14 
       }, 
       "showarrow": False, 
       "text": "Área Preservação Permanente", 
       "x": 0.555, 
       "y": 1.135 
      }, 
     ] 
    } 
} 
plotly.offline.iplot(fig) 

Donut Chart with

+1

으로 반복 사전 (x %)보다 작은 그룹을 "다른"범주로 ​​분류 이봐 요? – Aaron

답변

0

, 그것은 문자열과 배열을 모두 받아들입니다. "textposition"이 "auto"이면 레이블이 정상적으로 표시되고 "none"이면 레이블이 숨겨집니다.

{ 
     "values": dado_app_nascente, 
     "labels": label_app_nascente, 
     "domain": {"x": [0, .48]}, 
     "name": "area_entorno_nascente", 
     "textposition":"inside", 
     "hole": .4, 
     "type": "pie", 
     "marker": {'colors': c_app_nascente}, 
     "showlegend": False, 
     # vvv Here vvv 
     "textposition": ['auto','auto','auto','auto','none','none','none'] 
    }, 

그리고 우리는 손 전에 비율을 계산하여 textposition 배열을 생성 할 수 있습니다

def calculateTextpositions(values): 
    total = sum(values) 
    # Do not display percentages < 5% 
    return map(lambda v: 'none' if float(v)/total < 0.05 else 'auto', values) 

그럼 그냥 사용

"textposition": calculatetextpositions(dado_app_nascente), 

참조 : 데이터를 통해 https://plot.ly/python/reference/#pie-textposition

+0

도움 주셔서 감사합니다. 내 스크립트에서 몇 가지 문제가 있습니다. 나는 목록을 넣었고 (지도 ...) 잘 작동한다. – dogosousa

관련 문제