Python动态可视化模块Pynimate初体验
更新时间:2023年02月19日 09:27:06 作者:吃肉的小馒头
Pynimate是python第三方用于动态可视化的数据模块,是一位专攻 Python 语言的程序员开发的安装包。本文将通过几个简单的示例,讲解一下Pynimate的使用方法,需要的可以参考一下
Pynimate介绍
Pynimate是python第三方用于动态可视化的数据模块。
安装
pip install pynimate
实验示例
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("房地产投资累计亿元.csv",index_col=0)
# 可按自定义数据进行预处理
3.绘制图像
# 定义画布
cnv = nim.Canvas()
# 设置插值频率,可自定义调节
bar = nim.Barplot(df, "%Y-%m-%d", "1d")
# 使用回调函数接收对应格式化的年月信息
bar.set_time(callback=lambda i, datafier: datafier.data.index[i].strftime("%b, %Y"))
# 添加条形图到画布
cnv.add_plot(bar)
cnv.animate()
plt.show()
4.保存文件
# 两种格式存储,git和mp4
cnv.save("file", 24, "gif")
# cnv.save("file", 24, "mp4")
生成效果

持续关注模块来源github。
更典型的示例
用于对画图布局,边框,颜色等信息进行自定义和优化
代码示例:
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("房地产投资累计(亿元)", 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")
最终保存的动画效果

到此这篇关于Python动态可视化模块Pynimate初体验的文章就介绍到这了,更多相关Python Pynimate内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:
相关文章
Python中的测试模块unittest和doctest的使用教程
这篇文章主要介绍了Python中的测试模块unittest和doctest的使用教程,本文来自于IBM官方网站技术文档,需要的朋友可以参考下2015-04-04
Python dateutil库简化日期时间处理利器使用场景实践
在Python中,处理日期和时间是常见的任务之一,dateutil库是Python标准库中datetime模块的扩展,提供了许多方便的工具和函数,简化了日期和时间的操作2023-12-12
PyCharm2020.1.2社区版安装,配置及使用教程详解(Windows)
这篇文章主要介绍了PyCharm2020.1.2社区版安装,配置及使用教程(Windows),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-08-08


最新评论