Python+matplotlib+numpy实现在不同平面的二维条形图


Posted in Python onJanuary 02, 2018

在不同平面上绘制二维条形图。

本实例制作了一个3d图,其中有二维条形图投射到平面y=0,y=1,等。

演示结果:

Python+matplotlib+numpy实现在不同平面的二维条形图

Python+matplotlib+numpy实现在不同平面的二维条形图

完整代码:

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

# Fixing random state for reproducibility
np.random.seed(19680801)


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

colors = ['r', 'g', 'b', 'y']
yticks = [3, 2, 1, 0]
for c, k in zip(colors, yticks):
  # Generate the random data for the y=k 'layer'.
  xs = np.arange(20)
  ys = np.random.rand(20)

  # You can provide either a single color or an array with the same length as
  # xs and ys. To demonstrate this, we color the first bar of each set cyan.
  cs = [c] * len(xs)
  cs[0] = 'c'

  # Plot the bar graph given by xs and ys on the plane y=k with 80% opacity.
  ax.bar(xs, ys, zs=k, zdir='y', color=cs, alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# On the y axis let's only label the discrete values that we have data for.
ax.set_yticks(yticks)

plt.show()

脚本运行时间:(0分0.063秒)

总结

以上就是本文关于Python+matplotlib+numpy实现在不同平面的二维条形图的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

Python 相关文章推荐
python smtplib模块发送SSL/TLS安全邮件实例
Apr 08 Python
深入讲解Python中的迭代器和生成器
Oct 26 Python
Python基础教程之正则表达式基本语法以及re模块
Mar 25 Python
详解python中的json的基本使用方法
Dec 21 Python
python读取二进制mnist实例详解
May 31 Python
python导出chrome书签到markdown文件的实例代码
Dec 27 Python
TensorFlow 实战之实现卷积神经网络的实例讲解
Feb 26 Python
Django进阶之CSRF的解决
Aug 01 Python
python多线程调用exit无法退出的解决方法
Feb 18 Python
python 根据网易云歌曲的ID 直接下载歌曲的实例
Aug 24 Python
增大python字体的方法步骤
Jul 05 Python
Python实现Excel文件的合并(以新冠疫情数据为例)
Mar 20 Python
Python 实现淘宝秒杀的示例代码
Jan 02 #Python
python基于twisted框架编写简单聊天室
Jan 02 #Python
python http接口自动化脚本详解
Jan 02 #Python
详解用python实现简单的遗传算法
Jan 02 #Python
一个Python最简单的接口自动化框架
Jan 02 #Python
利用Hyperic调用Python实现进程守护
Jan 02 #Python
python实现TF-IDF算法解析
Jan 02 #Python
You might like
写php分页时出现的Fatal error的解决方法
2011/04/18 PHP
php快递单号查询接口使用示例
2014/05/05 PHP
PHP入门之常量简介和系统常量
2014/05/12 PHP
destoon会员注册提示“数据校验失败(2)”解决方法
2014/06/21 PHP
PHP token验证生成原理实例分析
2019/06/05 PHP
使用Git实现Laravel项目的自动化部署
2019/11/24 PHP
Array的push与unshift方法性能比较分析
2011/03/05 Javascript
JS保存和删除cookie操作 判断cookie是否存在
2013/11/13 Javascript
js判断是否为空和typeof的用法(详解)
2016/10/07 Javascript
AngularJS实现动态编译添加到dom中的方法
2016/11/04 Javascript
Javascript 数组去重的方法(四种)详解及实例代码
2016/11/24 Javascript
浅谈JavaScript的函数及作用域
2016/12/30 Javascript
Javascript中for循环语句的几种写法总结对比
2017/01/23 Javascript
vue.js中Vue-router 2.0基础实践教程
2017/05/08 Javascript
判断jQuery是否加载完成,没完成继续判断的解决方法
2017/12/06 jQuery
Angular网络请求的封装方法
2018/05/22 Javascript
使用RxJS更优雅地进行定时请求详析
2019/06/02 Javascript
详解vue中使用transition和animation的实例代码
2020/12/12 Vue.js
[03:57]2016完美“圣”典风云人物:rOtk专访
2016/12/09 DOTA
[49:07]VGJ.T vs Optic Supermajor小组赛D组 BO3 第二场 6.3
2018/06/04 DOTA
[01:02:46]VGJ.S vs NB 2018国际邀请赛小组赛BO2 第二场 8.18
2018/08/19 DOTA
python实现带验证码网站的自动登陆实现代码
2015/01/12 Python
Python CSV模块使用实例
2015/04/09 Python
Python爬取知乎图片代码实现解析
2019/09/17 Python
Anya Hindmarch官网:奢侈设计师手袋及配饰
2018/11/15 全球购物
.NET方向面试题
2014/11/20 面试题
酒店销售经理岗位职责
2014/01/31 职场文书
学校火灾防控方案
2014/06/09 职场文书
2014年最新学校运动会广播稿
2014/09/17 职场文书
践行党的群众路线心得体会
2014/11/05 职场文书
社区党建工作总结2015
2015/05/13 职场文书
傲慢与偏见电影观后感
2015/06/10 职场文书
学校运动会通讯稿
2015/07/18 职场文书
小程序后台PHP版本部署运行 LNMP+WNMP
2021/04/01 Servers
特别篇动画《总之就是非常可爱 ~制服~》PV公开,2022年夏季播出
2022/04/04 日漫
Python+Matplotlib图像上指定坐标的位置添加文本标签与注释
2022/04/11 Python