日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
啥?Python竟然也可以制作萌萌的手繪圖表

大家可能已經(jīng)習(xí)慣了用Matplotlib和seaborn來制作不同的圖表,但是今天要介紹一個(gè)非??岬腜ython手繪風(fēng)格的可視化包:cutecharts。

成都創(chuàng)新互聯(lián)公司長(zhǎng)期為上千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為振安企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站,振安網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

這個(gè)包可以用來生成以下幾種看起來像手繪的圖表,在某些場(chǎng)景下效果可能更好。這些可愛的圖表還具有交互性和動(dòng)態(tài)性。每當(dāng)鼠標(biāo)在圖表上懸停時(shí),數(shù)字就會(huì)顯示出來。而要?jiǎng)?chuàng)建這種圖表,你只需要幾行Python代碼。

目前,該庫支持五種圖表--條形圖、線形圖、餅圖、雷達(dá)圖和散點(diǎn)圖。它還支持圖表的組合。

在開始繪制可愛的圖表之前,我們需要安裝 cutechart 庫。

 
 
 
  1. $ pip install cutecharts 

安裝好后我們來嘗試畫下條形圖和線圖。首先創(chuàng)建下數(shù)據(jù),以某個(gè)城市的溫度數(shù)據(jù)為例。 

 
 
 
  1. #import library and data 
  2. import cutecharts.charts as ctcdf=pd.DataFrame({ ‘x’:[‘Sun.’,’Mon.’,’Tue.’,’Wed.’,’Thu.’,’Fri.’,’Sat.’], ‘y’:[14,15,17,20,22.3,23.7,24.8], ‘z’:[16,16.4,23.6,24.5,19.9,13.6,13.4]}) 

1、條形圖

代碼: 

 
 
 
  1. chart = ctc.Bar(‘Toronto Temperature’,width=’500px’,height=’400px’)
  2. chart.set_options( labels=list(df[‘x’]), x_label='Days', y_label='Temperature (Celsius)' , colors=[‘#1EAFAE’ for i in range(len(df))] )
  3. chart.add_series('This week',list(df[‘y’]))
  4. chart.render_notebook() 

效果:

在這個(gè)條形圖中,所有的條形圖都有相同的顏色。如果你想自定義每個(gè)條形圖的顏色,你只需要更改一行代碼。 

 
 
 
  1. chart = ctc.Bar(‘title’,width=’500px’,height=’400px’)
  2. chart.set_options( labels=list(df[‘x’]), x_label=”Days”, y_label=”Temperature (Celsius)” , colors=[‘#FFF1C9’,’#F7B7A3',’#EA5F89',’#9B3192',’#57167E’,’#47B39C’,’#00529B’] )
  3. chart.add_series(“This week”,list(df[‘y’]))
  4. chart.render_notebook() 

 

2、線圖

如果想觀察時(shí)間序列數(shù)據(jù)的變動(dòng)差異,線圖無疑更直觀。

代碼: 

 
 
 
  1. chart = ctc.Line(“Toronto Temperature”,width=’500px’,height=’400px’)
  2. chart.set_options( labels=list(df[‘x’]), x_label=”Days”, y_label=”Temperature (Celsius)” )
  3. chart.add_series(“This Week”, list(df[‘y’]))
  4. chart.add_series(“Last Week”, list(df[‘z’]))
  5. chart.render_notebook() 

 

還有一個(gè)特別的功能:

當(dāng)你把鼠標(biāo)懸停在圖表上時(shí),圖表會(huì)自動(dòng)顯示帶有數(shù)字的標(biāo)簽,而且還畫了一條虛線,這樣本周和上周的氣溫差異就更加直觀了。

3、雷達(dá)圖

要將線型圖改為雷達(dá)圖,你只需要將圖表類型改為ctc.Radar。

代碼: 

 
 
 
  1. chart = ctc.Radar(‘Toronto Temperature’,width=’700px’,height=’600px’)
  2. chart.set_options( labels=list(df[‘x’]), is_show_legend=True, #by default, it is true. You can turn it off. legend_pos=’upRight’ #location of the legend )
  3. chart.add_series(‘This week’,list(df[‘y’]))
  4. chart.add_series(“Last week”,list(df[‘z’]))
  5. chart.render_notebook() 

效果:

4、餅圖

我們需要另一個(gè)數(shù)據(jù)集來制作餅圖和甜甜圈圖。

創(chuàng)建數(shù)據(jù)集: 

 
 
 
  1. df=pd.DataFrame({‘x’:[‘Asia’, ‘Africa’, ‘Europe’, ‘North America’, ‘South America’, ‘Australia’], ‘y’:[59.69, 16, 9.94, 7.79, 5.68, 0.54]}) 

這個(gè)數(shù)據(jù)集包含了大洲名稱和人口占比。 

 
 
 
  1. chart = ctc.Pie(‘% of population by continent’,width=’500px’,height=’400px’)
  2. chart.set_options( labels=list(df[‘x’]), inner_radius=0 )
  3. chart.add_series(list(df[‘y’])) 
  4. chart.render_notebook() 

效果:

而且把餅圖變成甜甜圈圖也很容易。你只需要改變inner_radius的參數(shù)。

代碼: 

 
 
 
  1. df=pd.DataFrame({‘x’:[‘Asia’, ‘Africa’, ‘Europe’, ‘North America’, ‘South America’, ‘Australia’], ‘y’:[59.69, 16, 9.94, 7.79, 5.68, 0.54]})
  2. chart = ctc.Pie(‘% of population by continent’,width=’500px’,height=’400px’)
  3. chart.set_options( labels=list(df[‘x’]), inner_radius=0.6 )
  4. chart.add_series(list(df[‘y’])) 
  5. chart.render_notebook() 

 

5、散點(diǎn)圖

為了繪制散點(diǎn)圖,我將創(chuàng)建一個(gè)新的數(shù)據(jù)集。這次我們用到的是溫度和冰淇淋銷量數(shù)據(jù)。

數(shù)據(jù)集: 

 
 
 
  1. Temperature = [14.2,16.4,11.9,15.2,18.5,22.1,19.4,25.1,23.4,18.1,22.6,17.2]
  2. Sales = [215,325,185,332,406,522,412,614,544,421,445,408] 

散點(diǎn)圖代碼: 

 
 
 
  1. chart = ctc.Scatter(‘Ice Cream Sales vs Temperature’,width=’500px’,height=’600px’)
  2. chart.set_options( x_label=”Temperature (Celcius)”, y_label=”Icecream Sales” , colors=[‘#1EAFAE’], is_show_line = False, dot_size=1)
  3. chart.add_series(“Temperature”, [(z[0], z[1]) for z in zip(Temperature, Sales)])
  4. chart.render_notebook() 

 

6、組合圖

如果你想把多個(gè)圖表組合在一起,那么代碼也不復(fù)雜。 

 
 
 
  1. chart1 = ctc.Line(“Toronto Temperature”,width=’500px’,height=’400px’) 
  2. chart1.set_options( labels=list(df[‘x’]), x_label=”Days”, y_label=”Temperature (Celsius)” ) 
  3. chart1.add_series(“This Week”, list(df[‘y’])) 
  4. chart1.add_series(“Last Week”, list(df[‘z’])) 
  5. chart2 = ctc.Bar(‘Toronto Temperature’,width=’500px’,height=’400px’)
  6. chart2.set_options( labels=list(df[‘x’]), x_label=”Days”, y_label=”Temperature (Celsius)” , colors=[‘#1EAFAE’ for i in range(len(df))] )
  7. chart2.add_series(“This week”,list(df[‘y’]))
  8. chart2.add_series(“Last week”,list(df[‘z’]))
  9. page = Page()page.add(chart1, chart2)
  10. page.render_notebook() 

 

cutecharts這個(gè)包非常簡(jiǎn)單易用,如果你也喜歡這個(gè)風(fēng)格的圖表,就趕快試一下。


文章名稱:啥?Python竟然也可以制作萌萌的手繪圖表
當(dāng)前地址:http://www.dlmjj.cn/article/dpopies.html