python+matplotlib绘制3D条形图实例代码

yipeiwu_com6年前Python基础

本文分享的实例主要实现的是Python+matplotlib绘制一个有阴影和没有阴影的3D条形图,具体如下。

首先看看演示效果:

完整代码如下:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


# setup the figure and axes
fig = plt.figure(figsize=(8, 3))
ax1 = fig.add_subplot(121, projection='3d')
ax2 = fig.add_subplot(122, projection='3d')

# fake data
_x = np.arange(4)
_y = np.arange(5)
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()

top = x + y
bottom = np.zeros_like(top)
width = depth = 1

ax1.bar3d(x, y, bottom, width, depth, top, shade=True)
ax1.set_title('Shaded')

ax2.bar3d(x, y, bottom, width, depth, top, shade=False)
ax2.set_title('Not Shaded')

plt.show()

shade=True/False,使阴影可见/不可见。

总结

以上就是本文关于python+matplotlib绘制3D条形图实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

相关文章

python reverse反转部分数组的实例

python3中,list有个reverse函数,用来反转列表元素,但是如果想要反转部分元素呢? a = [1,2,3,4,5] a[0:3].reverse() # not wor...

python使用代理ip访问网站的实例

python使用代理ip访问网站的实例

实例如下所示: # -*- coding: UTF-8 -*- from urllib import request if __name__ == "__main__": #访问...

Python远程桌面协议RDPY安装使用介绍

RDPY 是基于 Twisted Python 实现的微软 RDP 远程桌面协议。 RDPY 提供了如下 RDP 和 VNC 支持: ●RDP Man In The Middle pro...

Python 实现异步调用函数的示例讲解

async_call.py #coding:utf-8 from threading import Thread def async_call(fn): def wrapper...

Python自定义类的数组排序实现代码

首先把实现方法写出来,其实很简单,只需要一句代码即可: 复制代码 代码如下: productlist.sort(lambda p1, p2:cmp(p1.getPrice(), p2.g...