最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)Matplotlib,Seaborn動(dòng)態(tài)數(shù)據(jù)圖的示例代碼

 更新時(shí)間:2022年05月06日 14:18:06   作者:pythonic生物人  
這篇文章主要為大家詳細(xì)介紹了如何讓Matplotlib、Seaborn的靜態(tài)數(shù)據(jù)圖動(dòng)起來,變得栩栩如生。文中的示例代碼講解詳細(xì),感興趣的小伙伴可以學(xué)習(xí)一下

Matplotlib

效果圖如下

主要使用matplotlib.animation.FuncAnimation,上核心代碼,

# 定義靜態(tài)繪圖函數(shù)
def draw_barchart(year):
    dff = df[df['year'].eq(year)].sort_values(by='value',
                                              ascending=True).tail(10)
    ax.clear()
    ax.barh(dff['name'],
            dff['value'],
            color=[colors[group_lk[x]] for x in dff['name']])
    dx = dff['value'].max() / 200
    for i, (value, name) in enumerate(zip(dff['value'], dff['name'])):
        ax.text(value - dx,
                i,
                name,
                size=14,
                weight=600,
                ha='right',
                va='bottom')
        ax.text(value - dx,
                i - .25,
                group_lk[name],
                size=10,
                color='#444444',
                ha='right',
                va='baseline')
        ax.text(value + dx,
                i,
                f'{value:,.0f}',
                size=14,
                ha='left',
                va='center')
    # 注釋文本
    ax.text(1,
            0.4,
            year,
            transform=ax.transAxes,
            color='#777777',
            size=46,
            ha='right',
            weight=800)
    ax.text(0,
            1.06,
            '單位 (每1000)',
            transform=ax.transAxes,
            size=12,
            color='#777777')
    ax.xaxis.set_major_formatter(ticker.StrMethodFormatter('{x:,.0f}'))
    ax.xaxis.set_ticks_position('top')
    ax.tick_params(axis='x', colors='#777777', labelsize=12)
    ax.set_yticks([])
    ax.margins(0, 0.01)
    ax.grid(which='major', axis='x', linestyle='-')
    ax.set_axisbelow(True)
    ax.text(0,
            1.12,
            '1500~2018年世界人口最多城市',
            transform=ax.transAxes,
            size=24,
            weight=600,
            ha='left')
    
    plt.box(False)


# 調(diào)用matplotlib.animation.FuncAnimation讓靜態(tài)圖動(dòng)起來
animator = animation.FuncAnimation(fig,
                                   draw_barchart,
                                   frames=range(1968, 2019))
# Jupyter Notebook里展示動(dòng)圖animation
HTML(animator.to_jshtml())

在繪圖數(shù)據(jù)部分改自己的數(shù)據(jù)既可為所欲為的使用了~

Seaborn

效果圖如下

代碼

import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import seaborn as sns
import numpy as np
import palettable


def get_data(i=0):
    x, y = np.random.normal(loc=i, scale=3, size=(2, 260))
    return x, y
x, y = get_data()


g = sns.JointGrid(x=x, y=y, size=4)
g.fig.set_size_inches(10, 8)
lim = (-10, 10)


def prep_axes(g, xlim, ylim):
    g.ax_joint.clear()
    g.ax_joint.set_xlim(xlim)
    g.ax_joint.set_ylim(ylim)
    g.ax_marg_x.clear()
    g.ax_marg_x.set_xlim(xlim)
    g.ax_marg_y.clear()
    g.ax_marg_y.set_ylim(ylim)
    plt.setp(g.ax_marg_x.get_xticklabels(), visible=False)
    plt.setp(g.ax_marg_y.get_yticklabels(), visible=False)
    plt.setp(g.ax_marg_x.yaxis.get_majorticklines(), visible=False)
    plt.setp(g.ax_marg_x.yaxis.get_minorticklines(), visible=False)
    plt.setp(g.ax_marg_y.xaxis.get_majorticklines(), visible=False)
    plt.setp(g.ax_marg_y.xaxis.get_minorticklines(), visible=False)
    plt.setp(g.ax_marg_x.get_yticklabels(), visible=False)
    plt.setp(g.ax_marg_y.get_xticklabels(), visible=False)


def animate(i):
    g.x, g.y = get_data(i)
    prep_axes(g, lim, lim)
    g.plot_joint(sns.kdeplot,
                 cmap='Paired')
    g.plot_marginals(sns.kdeplot, color='blue', shade=True)


frames = np.sin(np.linspace(0, 2 * np.pi, 17)) * 5
ani = matplotlib.animation.FuncAnimation(g.fig,
                                         animate,
                                         frames=frames,
                                         repeat=True)
HTML(ani.to_jshtml())

和Matplotlib代碼類似,不過多解釋。

到此這篇關(guān)于Python實(shí)現(xiàn)Matplotlib,Seaborn動(dòng)態(tài)數(shù)據(jù)圖的示例代碼的文章就介紹到這了,更多相關(guān)Python動(dòng)態(tài)數(shù)據(jù)圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python數(shù)據(jù)類型之String字符串實(shí)例詳解

    Python數(shù)據(jù)類型之String字符串實(shí)例詳解

    這篇文章主要介紹了Python數(shù)據(jù)類型之String字符串,結(jié)合實(shí)例形式詳細(xì)講解了Python字符串的概念、定義、連接、格式化、轉(zhuǎn)換、查找、截取、判斷等常見操作技巧,需要的朋友可以參考下
    2019-05-05
  • 使用pandas的box_plot去除異常值

    使用pandas的box_plot去除異常值

    今天小編就為大家分享一篇使用pandas的box_plot去除異常值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • 詳解OpenCV圖像的概念和基本操作

    詳解OpenCV圖像的概念和基本操作

    opencv最主要的的功能是用于圖像處理,所以圖像的概念貫穿了整個(gè)opencv,與其相關(guān)的核心類就是Mat。這篇文章主要介紹了OpenCV圖像的概念和基本操作,需要的朋友可以參考下
    2021-10-10
  • Pandas:Series和DataFrame刪除指定軸上數(shù)據(jù)的方法

    Pandas:Series和DataFrame刪除指定軸上數(shù)據(jù)的方法

    今天小編就為大家分享一篇Pandas:Series和DataFrame刪除指定軸上數(shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-11-11
  • Pandas分組聚合之groupby()、agg()方法的使用教程

    Pandas分組聚合之groupby()、agg()方法的使用教程

    今天看到pandas的聚合函數(shù)agg,比較陌生,平時(shí)的工作中處理數(shù)據(jù)的時(shí)候使用的也比較少,為了加深印象,總結(jié)一下使用的方法,下面這篇文章主要給大家介紹了關(guān)于Pandas分組聚合之groupby()、agg()方法的使用教程,需要的朋友可以參考下
    2023-01-01
  • Python裝飾器之類裝飾器詳解

    Python裝飾器之類裝飾器詳解

    本文將詳細(xì)介紹Python中類裝飾器的概念、使用方法以及應(yīng)用場(chǎng)景,并通過一個(gè)綜合詳細(xì)的例子展示如何使用類裝飾器,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • Python實(shí)現(xiàn)視頻轉(zhuǎn)圖片的兩種方案

    Python實(shí)現(xiàn)視頻轉(zhuǎn)圖片的兩種方案

    文章介紹了兩種Python視頻轉(zhuǎn)圖片的方案,方案1按幀提取,方案2按時(shí)間間隔提取,核心功能包括關(guān)鍵函數(shù)與參數(shù)的說明、實(shí)用優(yōu)化點(diǎn)和使用注意事項(xiàng),標(biāo)注工具推薦包括LabelImg、LabelMe和CVAT,需要的朋友可以參考下
    2026-02-02
  • Django視圖函數(shù)的具體使用

    Django視圖函數(shù)的具體使用

    這篇文章主要介紹了Django視圖函數(shù)的具體使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • python正則表達(dá)式匹配[]中間為任意字符的實(shí)例

    python正則表達(dá)式匹配[]中間為任意字符的實(shí)例

    今天小編就為大家分享一篇python正則表達(dá)式匹配[]中間為任意字符的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • 利用Python實(shí)現(xiàn)批量裁剪圖片

    利用Python實(shí)現(xiàn)批量裁剪圖片

    這篇文章主要為大家詳細(xì)介紹了如何基于Python如何批量裁剪圖片并保存,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,有需要的小伙伴可以了解一下
    2023-10-10

最新評(píng)論

玛多县| 武宁县| 镇原县| 仙居县| 醴陵市| 德化县| 大宁县| 新源县| 铅山县| 佳木斯市| 利辛县| 七台河市| 五家渠市| 峨眉山市| 社旗县| 安新县| 宁河县| 泸水县| 栾川县| 刚察县| 拉萨市| 分宜县| 怀宁县| 临洮县| 苏尼特右旗| 铜梁县| 芜湖市| 宾川县| 乌拉特后旗| 揭东县| 乌苏市| 微博| 进贤县| 甘洛县| 长阳| 宜章县| 宣威市| 临高县| 仁布县| 雷山县| 云林县|