数据可视化之美 |
您所在的位置:网站首页 › python数据可视化软件 › 数据可视化之美 |
可视化是数据描述的图形表示c;旨在一目了然地揭示数据中的复杂信息。数据可视化在讲故事中的重要性@R_520_9772@。 在可视化当中c;我们常用的方式有点、线、面c;或者说这几者组合。部分绘图结果可见下面链接: Python 画点线图、Python 画柱状图、Python 画柱状图(总结) 在可视化中最为复杂的要数动态图的绘制c;动态图能表达出更多的信息(如时间维)c;包含二维(xc;time)、三维(xc;yc;time)、四维(xc;yc;zc;time)数据中的信息。 同时c;动画可以有趣地展示某种现象。相比于静态图表c;人们更容易被动画和交互式的图表所吸引。 由于博主本身专业的限制c;只重点关注了地学的相关文献、代码c;其他专业也可借鉴本文中的相关动态图制作方法。 动图可视化作品举例在日常学习生活中c;可以发现有非常多精彩的动态图可视化作品c;这些动态图为工作的展现、数据的说明都起到锦上添花的效果。见下: Example1:该动图的左边反映的是缺氧区域随时间的变化c;右边反映的是空间的变化 Example3:这种动图也可用pandas_alive绘制c;见下 This animation shows the transport of air parcels conTinuously emitted from four point sources inside the canopy during a period of 2.5 hours for the simulation 该动图来源于SCI论文《地形对茂密森林内排放的气体在冠层内运输的影响》 Effects of topography on in-canopy transport of gases emitted within dense forests 接下来重点介绍GIF图的生成c;需要注意的是c;GIF的生成一般是需要安装imagemagick(图片处理工具)c;用pillow也行(但相对较有瑕疵)。 举例说明:基于matplotlib中的anamation Test1:移动的sin曲线(通过更新数据方式) import numpy as np from matplotlib import pyplot as plt from matplotlib.animation import FuncAnimation plt.style.use('seaborn-pastel') fig = plt.figure() ax = plt.axes(xlim=(0, 4), ylim=(-2, 2)) # 创建了一个图像窗口c;设置了坐标轴的范围 line, = ax.plot([], [], lw=3) # 建了一个空的line对象c;之后将通过更新line的数据c;实现动画效果。 def init(): # 初始化函数initc;这个函数其实什么也没干c;给了line对象空的数据 line.set_data([], []) return line, def animate(i): # 动画函数animatec;入参i是动画帧序号c;根据i计算新的sin曲线数据c;更新到line对象。 x = np.linspace(0, 4, 1000) y = np.sin(2 * np.pi * (x - 0.01 * i)) line.set_data(x, y) return line, anim = FuncAnimation(fig, animate, init_func=init, frames=100, interval=20, blit=True) # 利用之前所说的FuncAnimation()函数创建了对象animc;初始化时传入了figure对象c;init()函数和animate()函数c;以及帧数和更新时间。 # 循环一个周期c;也就是100帧c;就可以实现前后相接的循环效果了 anim.save('sine_wave_pillow.gif', writer='pillow') # writer 根据实际安装可选择李萨如图形见下: 预先计算的【图像列表】的动画图像 import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation fig = plt.figure() def f(x, y): return np.sin(x) + np.cos(y) x = np.linspace(0, 2 * np.pi, 120) y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1) # ims is a list of lists, each row is a list of artists to draw in the # current frame; here we are just animaTing one artist, the image, in # each frame ims = [] for i in range(60): x += np.pi / 15. y += np.pi / 20. im = plt.imshow(f(x, y), animated=True) ims.append([im]) ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True, repeat_delay=1000) ani.save('test_2d.gif', writer='pillow')备注:以上皆是利用matplotlib中的anamation绘制c;还可以利用上文提到的pandas_alive进行绘制 举例说明:基于pandas_alive Test5:x轴显示固定 import pandas as pd import pandas_alive elec_df = pd.read_csv("data/Aus_Elec_Gen_1980_2018.csv",index_col=0,parse_dates=[0],thousands=',') elec_df.fillna(0).plot_animated('./fixed-example.gif',period_fmt="%Y",title='Australian Electricity Generation sources 1980-2018',fixed_max=True,fixed_order=True)[1] 数据可视化: matplotlib绘制动态图及3维动画 [2] 【matplotlib】绘制动态图像 [3] GitHub pandas_alive |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |