2016-10-12 5 views
0

私はpandas、plotly、cuflinksを使ってデータフレームから生成しているグラフにカラースケールを適用しようとしています。パンダとCuflinkでPlotlyにカラースケールを適用する際の問題

私は特定のColorScaleのを使用しようとする場合、それは破壊だ:ここで

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 = cl.scales['9']['seq']['BuPu'] 
cs12 = cl.scales['12']['qual']['Paired'] 
HTML(cl.to_html(cs12)) 

私が使用してプロットを作成した場合

これは動作します:

「bupuは、」それは私が「CS12」と同じ、彼をしようとすると、しかし、私はエラーを取得し、素晴らしい作品3210
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モジュールを使用するためにはカラー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 
関連する問題