Python?"手繪風格"數(shù)據(jù)可視化方法實例匯總
前言
大家好,今天給大家?guī)砝L制“手繪風格”可視化作品的小技巧,主要涉及Python編碼繪制。主要內容如下:
Python-matplotlib 手繪風格圖表繪制
Python-cutecharts 手繪風格圖表繪制
Python-py-roughviz 手繪風格圖表繪制
Python-matplotlib 手繪風格圖表繪制
使用Python進行可視化繪制,首先想到的當然是Matplotlib,“手繪風格”的圖表繪制方法當然首選它。在Matplotlib中,matplotlib.pyplot.xkcd() 繪圖函數(shù)就可以進行手繪風圖表的繪制,下面小編通過具體樣例進行展示:
樣例一:
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 手繪風格圖表繪制
介紹完使用matplotlib繪制后,小編再介紹一個專門繪制“手繪風格”圖表的Python可視化庫-cutecharts。這個包可能有的小伙伴也有了解過,如果熟悉pyecharts的同學肯定會更加快速上手的。官網如下:https://github.com/cutecharts/cutecharts.py 。這里小編就直接列舉幾個例子,感興趣的同學可自行探索哈~
樣例一:
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()方法可使繪圖結果在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
這里這是基本的圖表繪制,實現(xiàn)定制化的屬性參數(shù)也都沒有介紹,小伙伴們可去官網查閱(由于沒詳細的官方文檔,大家可參考樣例和pyecharts的文檔)
Python-py-roughviz 手繪風格圖表繪制
這個和cutecharts包一樣,都是基于roughViz.js轉換編碼繪制的,官網為:https://github.com/charlesdong1991/py-roughviz 。由于所支持的圖表類型不是很多且各個圖標設置的參數(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
總結
到此這篇關于Python "手繪風格"數(shù)據(jù)可視化方法的文章就介紹到這了,更多相關Python 手繪風格數(shù)據(jù)可視化內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
- 利用Python進行數(shù)據(jù)可視化常見的9種方法!超實用!
- Python數(shù)據(jù)可視化 pyecharts實現(xiàn)各種統(tǒng)計圖表過程詳解
- 利用Python代碼實現(xiàn)數(shù)據(jù)可視化的5種方法詳解
- Python數(shù)據(jù)可視化庫seaborn的使用總結
- Python數(shù)據(jù)可視化:箱線圖多種庫畫法
- Python數(shù)據(jù)可視化之畫圖
- Python數(shù)據(jù)可視化:餅狀圖的實例講解
- Python數(shù)據(jù)可視化:泊松分布詳解
- Python數(shù)據(jù)可視化:冪律分布實例詳解
- python實現(xiàn)股票歷史數(shù)據(jù)可視化分析案例
相關文章
python神經網絡Batch?Normalization底層原理詳解
這篇文章主要為大家介紹了python神經網絡Batch?Normalization底層原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05在Python中實現(xiàn)函數(shù)重載的示例代碼
這篇文章主要介紹了在Python中實現(xiàn)函數(shù)重載的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-12-12在Python的struct模塊中進行數(shù)據(jù)格式轉換的方法
這篇文章主要介紹了在Python的struct模塊中進行數(shù)據(jù)格式轉換的方法,文中還給出了C語言和Python語言的數(shù)據(jù)類型比較,需要的朋友可以參考下2015-06-06python 使用raw socket進行TCP SYN掃描實例
這篇文章主要介紹了python 使用raw socket進行TCP SYN掃描實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05