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函数定义及传参方式详解(4种)

一、函数初识 1、定义:将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可。  2、好处:代码重用;保持一致性;可扩展性。 3、示例如下:    ...

python socket网络编程之粘包问题详解

python socket网络编程之粘包问题详解

一,粘包问题详情 1,只有TCP有粘包现象,UDP永远不会粘包 你的程序实际上无权直接操作网卡的,你操作网卡都是通过操作系统给用户程序暴露出来的接口,那每次你的程序要给远程发数据时,...

Python Mysql自动备份脚本

测试系统环境  Windows 2003   python 2.5.1  mysql ...

pytorch 转换矩阵的维数位置方法

例如: preds = to_numpy(preds)#preds是[2985x16x2] preds = preds.transpose(2, 1, 0)#preds[2x16x2...

Python的Django框架中使用SQLAlchemy操作数据库的教程

零、SQLAlchemy是什么? SQLAlchemy的官网上写着它的介绍文字: SQLAlchemy is the Python SQL toolkit and Object Rela...