Python?"手繪風(fēng)格"數(shù)據(jù)可視化方法實(shí)例匯總
前言
大家好,今天給大家?guī)砝L制“手繪風(fēng)格”可視化作品的小技巧,主要涉及Python編碼繪制。主要內(nèi)容如下:
Python-matplotlib 手繪風(fēng)格圖表繪制
Python-cutecharts 手繪風(fēng)格圖表繪制
Python-py-roughviz 手繪風(fēng)格圖表繪制
Python-matplotlib 手繪風(fēng)格圖表繪制
使用Python進(jìn)行可視化繪制,首先想到的當(dāng)然是Matplotlib,“手繪風(fēng)格”的圖表繪制方法當(dāng)然首選它。在Matplotlib中,matplotlib.pyplot.xkcd() 繪圖函數(shù)就可以進(jìn)行手繪風(fēng)圖表的繪制,下面小編通過具體樣例進(jìn)行展示:
樣例一:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
with plt.xkcd():
fig, ax = plt.subplots(figsize=(6.5,4),dpi=100)
ax = df.plot.bar(color=["#BC3C28","#0972B5"],ec="black",rot=15,ax=ax)
ax.set_ylim((0, 100))
ax.legend(frameon=False)
ax.set_title("EXAMPLE01 OF MATPLOTLIB.XKCD()",pad=20)
ax.text(.8,-.22,'Visualization by DataCharm',transform = ax.transAxes,
ha='center', va='center',fontsize = 10,color='black')

Example01 of matplotlib.xkcd()
樣例二:
df = pd.DataFrame({
'x': [1, 2, 2.5, 3, 3.5, 4, 5],
'y': [4, 4, 4.5, 5, 5.5, 6, 6],
})
with plt.xkcd():
fig, ax = plt.subplots(figsize=(6.5,4),dpi=100)
ax = df.plot.kde(color=["#BC3C28","#0972B5"],ax=ax)
ax.set_ylim((0, 0.4))
ax.legend(frameon=False)
ax.set_title("EXAMPLE02 OF MATPLOTLIB.XKCD()",pad=20)
ax.text(.8,-.22,'Visualization by DataCharm',transform = ax.transAxes,
ha='center', va='center',fontsize = 10,color='black')

Example02 of matplotlib.xkcd()
樣例三:
with plt.xkcd():
fig, ax = plt.subplots(figsize=(6.5,4),dpi=100)
ax.spines["right"].set_color('none')
ax.spines["top"].set_color('none')
ax.set_xticks([])
ax.set_yticks([])
ax.set_ylim([-30, 10])
data = np.ones(100)
data[70:] -= np.arange(30)
ax.annotate(
'THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED',
xy=(70, 1), arrowprops=dict(arrowstyle='->'), xytext=(15, -10))
ax.plot(data,color="#BC3C28")
ax.set_xlabel('time')
ax.set_ylabel('my overall health')
ax.set_title("EXAMPLE03 OF MATPLOTLIB.XKCD()")
ax.text(.8,-.15,'Visualization by DataCharm',transform = ax.transAxes,
ha='center', va='center',fontsize = 10,color='black')

Example03 of matplotlib.xkcd()
Python-cutecharts 手繪風(fēng)格圖表繪制
介紹完使用matplotlib繪制后,小編再介紹一個專門繪制“手繪風(fēng)格”圖表的Python可視化庫-cutecharts。這個包可能有的小伙伴也有了解過,如果熟悉pyecharts的同學(xué)肯定會更加快速上手的。官網(wǎng)如下:https://github.com/cutecharts/cutecharts.py 。這里小編就直接列舉幾個例子,感興趣的同學(xué)可自行探索哈~
樣例一:
from cutecharts.charts import Bar
from cutecharts.components import Page
from cutecharts.faker import Faker
def bar_base() -> Bar:
chart = Bar("Bar-cutecharts基本示例01")
chart.set_options(labels=Faker.choose(), x_label="I'm xlabel", y_label="I'm ylabel")
chart.add_series("series-A", Faker.values())
return chart
bar_base().render_notebook()
注:render_notebook()方法可使繪圖結(jié)果在jupyter notebook 中顯示。

樣例二:
from cutecharts.charts import Line
from cutecharts.components import Page
from cutecharts.faker import Faker
def line_base() -> Line:
chart = Line("Line-cutecharts基本示例02")
chart.set_options(labels=Faker.choose(), x_label="I'm xlabel", y_label="I'm ylabel")
chart.add_series("series-A", Faker.values())
chart.add_series("series-B", Faker.values())
return chart
line_base().render_notebook()

Example02 of cutecharts
樣例三:
from cutecharts.charts import Pie
from cutecharts.components import Page
from cutecharts.faker import Faker
def pie_base() -> Pie:
chart = Pie("Pie-cutecharts基本示例03")
chart.set_options(labels=Faker.choose(),legend_pos="upRight")
chart.add_series(Faker.values())
return chart
pie_base().render_notebook()

Example03 of cutecharts
這里這是基本的圖表繪制,實(shí)現(xiàn)定制化的屬性參數(shù)也都沒有介紹,小伙伴們可去官網(wǎng)查閱(由于沒詳細(xì)的官方文檔,大家可參考樣例和pyecharts的文檔)
Python-py-roughviz 手繪風(fēng)格圖表繪制
這個和cutecharts包一樣,都是基于roughViz.js轉(zhuǎn)換編碼繪制的,官網(wǎng)為:https://github.com/charlesdong1991/py-roughviz 。由于所支持的圖表類型不是很多且各個圖標(biāo)設(shè)置的參數(shù)也不夠完善,這里小編直接給出兩個樣例,感興趣的小伙伴可自行探索哈~
樣例一:
from roughviz.charts.bar import Bar
data = {
"labels": ["North", "South", "East", "West"],
"values": [10, 5, 8, 3]
}
bar = Bar(data=data, title="Bar-roughviz基本示例01", title_fontsize=3)
bar.set_options(xlabel="Region", ylabel="Number", color="orange")
bar.show()

Example01 of roughviz
樣例二:
from roughviz.charts.donut import Donut
donut = Donut(data={"labels": ['a', 'b'], "values": [10, 20]}, title="Donut-roughviz基本示例02", title_fontsize=3)
donut.show()

Example02 of roughviz
總結(jié)
到此這篇關(guān)于Python "手繪風(fēng)格"數(shù)據(jù)可視化方法的文章就介紹到這了,更多相關(guān)Python 手繪風(fēng)格數(shù)據(jù)可視化內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 利用Python進(jìn)行數(shù)據(jù)可視化常見的9種方法!超實(shí)用!
- Python數(shù)據(jù)可視化 pyecharts實(shí)現(xiàn)各種統(tǒng)計圖表過程詳解
- 利用Python代碼實(shí)現(xiàn)數(shù)據(jù)可視化的5種方法詳解
- Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)
- Python數(shù)據(jù)可視化:箱線圖多種庫畫法
- Python數(shù)據(jù)可視化之畫圖
- Python數(shù)據(jù)可視化:餅狀圖的實(shí)例講解
- Python數(shù)據(jù)可視化:泊松分布詳解
- Python數(shù)據(jù)可視化:冪律分布實(shí)例詳解
- python實(shí)現(xiàn)股票歷史數(shù)據(jù)可視化分析案例
相關(guān)文章
Python3 文章標(biāo)題關(guān)鍵字提取的例子
今天小編就為大家分享一篇Python3 文章標(biāo)題關(guān)鍵字提取的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08
Python使用Tkinter實(shí)現(xiàn)機(jī)器人走迷宮
這篇文章主要為大家詳細(xì)介紹了Python使用Tkinter實(shí)現(xiàn)機(jī)器人走迷宮,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01
Python enumerate() 函數(shù)如何實(shí)現(xiàn)索引功能
這篇文章主要介紹了Python enumerate() 函數(shù)如何實(shí)現(xiàn)索引功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-06-06
Python實(shí)現(xiàn)文件按照日期命名的方法
這篇文章主要介紹了Python實(shí)現(xiàn)文件按照日期命名的方法,涉及Python針對文件的遍歷、讀寫及時間操作相關(guān)技巧,需要的朋友可以參考下2015-07-07
Python如何使用logging為Flask增加logid
這篇文章主要介紹了Python如何使用logging為Flask增加logid,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下2021-03-03

