概述
matplotlib库是python最著名的绘图库,它提供了一整套和matlab相似的命令API,适合交互式地进行制图。并且在下面链接中有上百幅缩略图,打开之后都有源程序。因此如果你需要绘制某种类型的图,只需要在这个页面中浏览/复制/粘贴一下,基本上都能搞定。http://matplotlib.org/gallery.html
首先主要看mplot3d toolkit库
demo1
导入库函数
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
参数设置为3D属性
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
c为四种颜色 ,z为Z轴的位置
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
xs = np.arange(20)
ys = np.random.rand(20)
# You can provide either a single color or an array. To demonstrate this,
# the first bar of each set will be colored cyan.
cs = [c] * len(xs)
cs[0] = 'c'
ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)
X,Y,Z轴标注
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
运行结果如下:



以上为三个方向视图。
最后
以上就是难过纸鹤为你收集整理的Python编程-matplotlib3D直方图绘制的全部内容,希望文章能够帮你解决Python编程-matplotlib3D直方图绘制所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复