日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

优雅的 Python 动态图工具

發布時間:2024/1/18 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 优雅的 Python 动态图工具 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

作者 |?pythonic生物人

來源 |?pythonic生物人

數據動態圖怎么做,效果圖,

多子圖聯動競賽圖

安裝

pip?install?pandas_alive#或者 conda?install?pandas_alive?-c?conda-forge

玩起來

支持數據數據格式如下,

使用方法類似pandas。

動態地圖

結合geopandas,

動態水平bar

import?pandas?as?pd import?pandas_alive import?matplotlib.pyplot?as?pltplt.style.use('ggplot')#讀入數據 elec_df?=?pd.read_csv("Aus_Elec_Gen_1980_2018.csv",index_col=0,parse_dates=[0],thousands=',')#定義求和def def?current_total(values):total?=?values.sum()s?=?f'Total?:?{int(total)}'return?{'x':?.85,?'y':?.2,?'s':?s,?'ha':?'right',?'size':?11}#缺省值0填充、繪圖 elec_df.fillna(0).tail(n=10).plot_animated('electricity-generated-australia.gif',??#保存gif名稱period_fmt="%d/%m/%Y",??#動態更新圖中時間戳title='Australian?Electricity?Sources?1980-2018',??#標題perpendicular_bar_func='mean',??#添加均值輔助線period_summary_func=current_total,??#匯總cmap='Set1',??#定義調色盤n_visible=5,??#柱子顯示數orientation='h',#柱子方向 )

動態垂直bar

動態折線

elec_df.diff().fillna(0).tail(n=10).plot_animated(filename='line-chart.gif',kind='line',#指定折線模式cmap='Set1',period_label={'x':?0.25,'y':?0.9},line_width=1,add_legend=True,fill_under_line_color='#01a2d9')

動態累積bar

import?pandas_alive covid_df.sum(axis=1).fillna(0).tail(n=10).plot_animated(filename='sumbar-chart.gif',kind='bar',???#指定bar模式cmap='Set1',??#定義調色盤period_label={'x':?0.1,'y':?0.9},orientation='h',enable_progress_bar=True,steps_per_period=2,interpolate_period=True,period_length=200)

動態散點圖

import?pandas?as?pd import?pandas_alive#max散點數據 max_temp_df?=?pd.read_csv("Newcastle_Australia_Max_Temps.csv",parse_dates={"Timestamp":?["Year",?"Month",?"Day"]}, )#min散點數據 min_temp_df?=?pd.read_csv("Newcastle_Australia_Min_Temps.csv",parse_dates={"Timestamp":?["Year",?"Month",?"Day"]}, )#按時間戳merge?max/min數據 merged_temp_df?=?pd.merge_asof(max_temp_df,?min_temp_df,?on="Timestamp")merged_temp_df.index?=?pd.to_datetime(merged_temp_df["Timestamp"].dt.strftime('%Y/%m/%d'))keep_columns?=?["Minimum?temperature?(Degree?C)",?"Maximum?temperature?(Degree?C)" ]merged_temp_df.head(n=5000)[keep_columns].resample("Y").mean().plot_animated(filename='scatter-chart.gif',cmap='Set1',?kind="scatter",#指定散點模式size=10,title='Max?&?Min?Temperature?Newcastle,?Australia')

動態氣泡圖

import?pandas_alivemulti_index_df?=?pd.read_csv("multi.csv",?header=[0,?1],?index_col=0)multi_index_df.index?=?pd.to_datetime(multi_index_df.index,?dayfirst=True)map_chart?=?multi_index_df.tail(n=40).plot_animated(kind="bubble",??#指定氣泡模式filename="bubble-chart.gif",x_data_label="Longitude",y_data_label="Latitude",size_data_label="Cases",color_data_label="Cases",vmax=5,steps_per_period=1,interpolate_period=True,period_length=500,dpi=150)

多子圖一起動

這部分可以結合matplotlib的多子圖繪制,實現各種個性化動圖,核心代碼如下,

往期回顧

太卷了!AI 高數考試正確率81%

數據分析你選Pandas還是選SQL?

2D變身3D,來看英偉達的AI“新”魔法!

如何用 Python 實現景區安防系統?

分享 點收藏 點點贊 點在看

總結

以上是生活随笔為你收集整理的优雅的 Python 动态图工具的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。