2016-10-12 3 views
0

저는 plandly, cuflinks를 사용하여 데이터 프레임에서 생성하는 그래프에 컬러 스케일을 적용하려고합니다.팬더 및 Cuflinks로 Plotly에 컬러 스케일을 적용하는 데 문제가 있습니다

내가 어떤 colorscale 사용하려고하면 그것은 깨고 :

bupu = cl.scales['9']['seq']['BuPu'] 
cs12 = cl.scales['12']['qual']['Paired'] 
HTML(cl.to_html(cs12)) 

을 내가 사용 플롯을 만드는 경우 : 여기

import pandas as pd 
import cufflinks as cf 
import colorlover as cl 
from plotly.offline import download_plotlyjs, init_notebook_mode,plot,iplot 
from IPython.display import HTML 

init_notebook_mode(connected=True) 
cf.go_offline() 

을 내가 같이 잘 표시 할 수 있습니다 둘 다 내 colorscales이 있습니다

이 작동 : 'bupu는'그것은 내가 오류가 'CS12'와 같은 자신을 시도하지만 경우에, 좋은 작품

df.iplot(kind='bar',colorscale='bupu') 

이되지 않습니다

df.iplot(kind='bar',colorscale='cs12') 

KeyError: 'cs12'

답변

1

From the documentation :

colorscale must be an array containing arrays mapping a normalized value to an rgb, rgba, hex, hsl, hsv, or named color string. [...]

Alternatively, colorscale may be a palette name string of the following list: Greys, YlGnBu, Greens, YlOrRd, Bluered, RdBu, Reds, Blues, Picnic, Rainbow, Portland, Jet, Hot, Blackbody, Earth, Electric, Viridis

colorlover 모듈을 사용하기 위해서는 당신 color arr을 만들 수있다. 예를 들어, 변수를 colorscale에 할당하십시오.

import colorlover, plotly 

cs12 = colorlover.scales['12']['qual']['Paired'] 

plotly.plotly.plot(data=[{ 
    'colorscale': cs12 
    'z': [[10, 100.625, 1200.5, 150.625, 2000], 
     [5000.625, 60.25, 8.125, 100000, 150.625], 
     [2000.5, 300.125, 50., 8.125, 12.5], 
     [10.625, 1.25, 3.125, 6000.25, 100.625], 
     [0, 0.625, 2.5, 50000.625, 10]], 
    'type': 'heatmap' 
}]) 
1
난 그냥 내 자신의 사용자 정의 팔레트를 생성

mycolors = ['#F81106','#FA726C','#F8C1BE', 
      '#137503','#54B644','#B2F5A7', 
      '#051E9B','#4358C0','#A6B3F9', 
      '#9C06A0','#C34BC6','#F3A1F6', 
      '#A07709','#CDA742','#F4DC9D', 
      '#08A59E','#4DD5CE','#AAF7F3'] 

colors=mycolors 
관련 문제