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

Python動(dòng)態(tài)可視化模塊Pynimate初體驗(yàn)

 更新時(shí)間:2023年02月19日 09:27:06   作者:吃肉的小饅頭  
Pynimate是python第三方用于動(dòng)態(tài)可視化的數(shù)據(jù)模塊,是一位專攻?Python?語言的程序員開發(fā)的安裝包。本文將通過幾個(gè)簡(jiǎn)單的示例,講解一下Pynimate的使用方法,需要的可以參考一下

Pynimate介紹

Pynimate是python第三方用于動(dòng)態(tài)可視化的數(shù)據(jù)模塊。

安裝

pip install pynimate

實(shí)驗(yàn)示例

from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
import os

import pynimate as nim
# 用于顯示中文
import matplotlib as mpl
mpl.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False 

2.讀取csv文件

df = pd.read_csv("房地產(chǎn)投資累計(jì)億元.csv",index_col=0)
# 可按自定義數(shù)據(jù)進(jìn)行預(yù)處理

3.繪制圖像

# 定義畫布
cnv = nim.Canvas()
# 設(shè)置插值頻率,可自定義調(diào)節(jié)
bar = nim.Barplot(df, "%Y-%m-%d", "1d")
# 使用回調(diào)函數(shù)接收對(duì)應(yīng)格式化的年月信息
bar.set_time(callback=lambda i, datafier: datafier.data.index[i].strftime("%b, %Y"))
# 添加條形圖到畫布
cnv.add_plot(bar)
cnv.animate()
plt.show()

4.保存文件

# 兩種格式存儲(chǔ),git和mp4
cnv.save("file", 24, "gif")
# cnv.save("file", 24, "mp4")

生成效果

持續(xù)關(guān)注模塊來源github

更典型的示例

用于對(duì)畫圖布局,邊框,顏色等信息進(jìn)行自定義和優(yōu)化

代碼示例:

def post_update(ax, i, datafier, bar_attr):
    ax.spines["top"].set_visible(False)
    ax.spines["right"].set_visible(False)
    ax.spines["bottom"].set_visible(False)
    ax.spines["left"].set_visible(False)
    ax.set_facecolor("#001219")

cnv = nim.Canvas(figsize=(12.8, 7.2), facecolor="#001219")
bar = nim.Barplot(
    df2, "%Y-%m", "1d", post_update=post_update, rounded_edges=True, grid=False, n_bars=31
)
bar.set_title("房地產(chǎn)投資累計(jì)(億元)", color="w", weight=600)
# bar.set_xlabel("xlabel", color="w")
bar.set_time(
    callback=lambda i, datafier: datafier.data.index[i].strftime("%b, %Y"), color="w"
)

bar.set_bar_annots(color="w", size=13)
bar.set_xticks(colors="w", length=0, labelsize=13)
bar.set_yticks(colors="w", labelsize=13)
bar.set_bar_border_props(
    edge_color="black", pad=0.1, mutation_aspect=1, radius=0.2, mutation_scale=0.6
)
cnv.add_plot(bar)
cnv.animate()
# plt.show()
cnv.save("example3", 24, "gif")

最終保存的動(dòng)畫效果

到此這篇關(guān)于Python動(dòng)態(tài)可視化模塊Pynimate初體驗(yàn)的文章就介紹到這了,更多相關(guān)Python Pynimate內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論