欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python?"手繪風(fēng)格"數(shù)據(jù)可視化方法實(shí)例匯總

 更新時(shí)間:2022年02月10日 09:32:36   作者:Python學(xué)習(xí)與數(shù)據(jù)挖掘  
這篇文章主要給大家介紹了關(guān)于Python?"手繪風(fēng)格"數(shù)據(jù)可視化方法實(shí)現(xiàn)的相關(guān)資料,本文分別給大家?guī)砹薖ython-matplotlib手繪風(fēng)格圖表繪制、Python-cutecharts手繪風(fēng)格圖表繪制以及Python-py-roughviz手繪風(fēng)格圖表繪制,需要的朋友可以參考下

前言

大家好,今天給大家?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繪制后,小編再介紹一個(gè)專門繪制“手繪風(fēng)格”圖表的Python可視化庫(kù)-cutecharts。這個(gè)包可能有的小伙伴也有了解過,如果熟悉pyecharts的同學(xué)肯定會(huì)更加快速上手的。官網(wǎng)如下:https://github.com/cutecharts/cutecharts.py 。這里小編就直接列舉幾個(gè)例子,感興趣的同學(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)格圖表繪制

這個(gè)和cutecharts包一樣,都是基于roughViz.js轉(zhuǎn)換編碼繪制的,官網(wǎng)為:https://github.com/charlesdong1991/py-roughviz 。由于所支持的圖表類型不是很多且各個(gè)圖標(biāo)設(shè)置的參數(shù)也不夠完善,這里小編直接給出兩個(gè)樣例,感興趣的小伙伴可自行探索哈~

樣例一:

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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論