成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

啥?Python竟然也可以制作萌萌的手繪圖表

開發 后端
大家可能已經習慣了用Matplotlib和seaborn來制作不同的圖表,但是今天要介紹一個非常酷的Python手繪風格的可視化包:cutecharts。

大家可能已經習慣了用Matplotlib和seaborn來制作不同的圖表,但是今天要介紹一個非常酷的Python手繪風格的可視化包:cutecharts。

 

啥?Python竟然也可以制作萌萌的手繪圖表

 

這個包可以用來生成以下幾種看起來像手繪的圖表,在某些場景下效果可能更好。這些可愛的圖表還具有交互性和動態性。每當鼠標在圖表上懸停時,數字就會顯示出來。而要創建這種圖表,你只需要幾行Python代碼。

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

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

  1. $ pip install cutecharts 

安裝好后我們來嘗試畫下條形圖和線圖。首先創建下數據,以某個城市的溫度數據為例。 

  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() 

效果:

 

啥?Python竟然也可以制作萌萌的手繪圖表

 

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

  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() 

 

啥?Python竟然也可以制作萌萌的手繪圖表

 

 

2、線圖

如果想觀察時間序列數據的變動差異,線圖無疑更直觀。

代碼: 

  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() 

 

啥?Python竟然也可以制作萌萌的手繪圖表

 

 

還有一個特別的功能:

當你把鼠標懸停在圖表上時,圖表會自動顯示帶有數字的標簽,而且還畫了一條虛線,這樣本周和上周的氣溫差異就更加直觀了。

3、雷達圖

要將線型圖改為雷達圖,你只需要將圖表類型改為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() 

效果:

 

啥?Python竟然也可以制作萌萌的手繪圖表

 

4、餅圖

我們需要另一個數據集來制作餅圖和甜甜圈圖。

創建數據集: 

  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]}) 

這個數據集包含了大洲名稱和人口占比。 

  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() 

效果:

 

啥?Python竟然也可以制作萌萌的手繪圖表

 

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

代碼: 

  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() 

 

啥?Python竟然也可以制作萌萌的手繪圖表

 

5、散點圖

為了繪制散點圖,我將創建一個新的數據集。這次我們用到的是溫度和冰淇淋銷量數據。

數據集: 

  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] 

散點圖代碼: 

  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() 

 

啥?Python竟然也可以制作萌萌的手繪圖表

 

6、組合圖

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

  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() 

 

啥?Python竟然也可以制作萌萌的手繪圖表

 

 

cutecharts這個包非常簡單易用,如果你也喜歡這個風格的圖表,就趕快試一下。

 

責任編輯:龐桂玉 來源: 光明網
相關推薦

2017-02-07 11:35:26

Android動畫蠟燭動畫

2021-06-01 17:03:03

辦公

2014-09-10 16:08:53

蘋果發布會iPhone6

2009-12-09 09:45:35

袁萌Linux

2014-10-08 10:42:08

萌碼編程

2014-10-10 10:13:52

91助手

2014-11-05 09:30:18

萌碼

2009-12-09 09:43:27

2010-01-05 10:18:10

袁萌Linux

2009-11-09 10:01:00

2009-12-21 13:50:55

Linux桌面

2009-11-16 09:48:50

袁萌Linux桌面Linux

2016-04-01 09:52:30

Autolayout約束動畫ios

2009-09-23 10:23:49

2009-12-09 17:06:15

小Linux

2009-12-01 08:44:09

袁萌Linux操作系統

2009-12-25 09:34:54

袁萌Linux

2011-09-15 09:12:00

程序員蘋果

2011-08-22 09:35:34

2009-11-13 09:30:47

袁萌Linux桌面Linux
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲欧美日韩国产 | 久久久久亚洲av毛片大全 | 一区二区三区影院 | 中文字幕欧美日韩一区 | 久久久婷婷 | 亚洲精品在线视频 | 欧美视频在线播放 | 国产情侣在线看 | 午夜影院在线观看 | 天天操网 | 亚洲欧美中文日韩在线v日本 | 日本久久久一区二区三区 | 亚州无限乱码 | 欧美成人精品激情在线观看 | 中文字幕在线播放不卡 | 男女网站视频 | 精品国产一区二区三区性色av | 欧美日韩成人一区二区 | 久久成人精品一区二区三区 | 亚洲三区视频 | 久久久久久国产精品mv | 精品日韩一区 | 精品久久久久久久久久久久 | 99久久亚洲 | 欧美一区二区成人 | 日韩一区二区在线播放 | 国产精品黄色 | 午夜精品久久久久久久久久久久 | 国产精品久久九九 | 爱爱免费视频 | 宅女噜噜66国产精品观看免费 | 欧美日韩精品在线一区 | 成人午夜免费福利视频 | 天天夜夜操 | 成人免费一区二区三区牛牛 | 91黄在线观看 | 欧美中文一区 | 精品久草 | 小视频你懂得 | 综合久久综合久久 | 亚洲精品高清视频在线观看 |