matplotlib画图——条形图
一.单条
import numpy as np
import matplotlib.pyplot as plt N = 5
y1 = [20, 10, 30, 25, 15]
y2 = [15, 14, 34 ,10,5]
index = np.arange(5) bar_width = 0.3
plt.bar(index , y1, width=0.3 , color='y')
plt.bar(index , y2, width=0.3 , color='b' ,bottom=y1)
plt.show()
二.误差棒
mean_values = [1,2,3]
#误差范围
variance = [0.2,0.4,0.5]
bar_label = ['bar1','bar2','bar3'] x_pos = list(range(len(bar_label)))
plt.bar(x_pos,mean_values,yerr=variance,alpha=0.7)
max_y = max(zip(mean_values,variance))
plt.ylim([0,max_y[0]+max_y[1]*1.2])
plt.ylabel('variable y')
plt.xticks(x_pos,bar_label)
plt.show()
三.背靠背
x1 = np.array([1,2,3])
x2 = np.array([2,2,3]) bar_labels = ['bar1','bar2','bar3']
fig = plt.figure(figsize=(8,6))
y_pos = np.arange(len(x1))
y_pos = [x for x in y_pos]
#bar竖着 barh横着
plt.barh(y_pos,x1,color='g',alpha=0.5)
plt.barh(y_pos,-x1,color='b',alpha=0.5)
#x y轴范围限制
plt.xlim(-max(x2)-1,max(x1)+1)
plt.ylim(-1,len(x1)+1)
plt.show()
四.三条
green_data = [1,2,3]
blue_data = [3,2,1]
red_data = [2,3,1]
labels = ['group 1','group 2','group 3'] pos = list(range(len(green_data)))
width = 0.2
fig,ax = plt.subplots(figsize=(8,6)) plt.bar(pos, green_data,width,alpha=0.5,color='g',label=labels[0])
plt.bar([p+width for p in pos], green_data,width,alpha=0.5,color='b',label=labels[1])
plt.bar([p+width*2 for p in pos], green_data,width,alpha=0.5,color='r',label=labels[2])
plt.show()
五.正负
x = np.arange(5)
#(-5,5)随机五个数
y = np.random.randint(-5,5,5)
fig,ax = plt.subplots()
v_bars = ax.bar(x,y,color='lightblue')
for bar,height in zip(v_bars,y):
if height < 0:
bar.set(edgecolor = 'darkred', color = 'green', linewidth = 3)
六.标线
#随机五个数
data = range(200,225,5)
#坐标标注
bar_labels = ['a','b','c','d','e']
#条形的长宽
fig = plt.figure(figsize=(10,8))
#5个
y_pos = np.arange(len(data))
plt.yticks(y_pos, bar_labels, fontsize=16)
bars = plt.barh(y_pos,data,alpha = 0.5,color = 'g')
#按照最小值的位置画垂直的竖线
plt.vlines(min(data), -1, len(data)+0.5,linestyles='dashed')
#把值写到后面
for b,d in zip(bars,data):
plt.text(b.get_width() + b.get_width()*0.05,
b.get_y()+b.get_height()/2,
'{0:.2%}'.format(d/min(data)))
plt.show()
另:折线填充
x = np.random.randn(100).cumsum()
y = np.linspace(0,10,100) fig,ax = plt.subplots()
#折线图填充
ax.fill_between(x,y,color='lightblue')
x = np.linspace(0,10,200)
y1 = 2*x + 1
y2 = 3*x +1.2
y_mean = 0.5*x*np.cos(2*x) + 2.5*x + 1.1
fig,ax = plt.subplots()
ax.fill_between(x,y1,y2,color='red')
ax.plot(x,y_mean,color='black')
matplotlib画图——条形图的更多相关文章
- python matplotlib画图产生的Type 3 fonts字体没有嵌入问题
ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...
- 使用python中的matplotlib 画图,show后关闭窗口,继续运行命令
使用python中的matplotlib 画图,show后关闭窗口,继续运行命令 在用python中的matplotlib 画图时,show()函数总是要放在最后,且它阻止命令继续往下运行,直到1.0 ...
- matplotlib 画图
matplotlib 画图 1. 画曲线图 Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0 ...
- matplotlib画图
matplotlib画图 import numpy as np import matplotlib.pyplot as plt x1=[20,33,51,79,101,121,132,145,162, ...
- python3 使用matplotlib画图出现中文乱码的情况
python3使用matplotlib画图,因python3默认使用中unicode编码,所以在写代码时不再需要写 plt.xlabel(u’人数’),而是直接写plt.xlabel(‘人数’). 注 ...
- matplotlib画图实例:pyplot、pylab模块及作图參数
http://blog.csdn.net/pipisorry/article/details/40005163 Matplotlib.pyplot画图实例 {使用pyplot模块} matplotli ...
- python使用matplotlib画图
python使用matplotlib画图 matplotlib库是python最著名的画图库.它提供了一整套和matlab类似的命令API.十分适合交互式地进行制图. 先介绍了怎样使用matplotl ...
- matplotlib画图报错This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
之前用以下代码将实验结果用matplotlib show出来 plt.plot(np.arange(len(aver_reward_list)), aver_reward_list) plt.ylab ...
- matplotlib画图出现乱码情况
python3使用matplotlib画图,因python3默认使用中unicode编码,所以在写代码时不再需要写 plt.xlabel(u’人数’),而是直接写plt.xlabel(‘人数’). 注 ...
随机推荐
- liunx 环境下安装 Eclipse C++
第一步:首先安装JDK 进入JDK官网:https://www.oracle.com/technetwork/java/javase/downloads/index.html 下载对应的jdk 注意 ...
- 18.AutoMapper 之条件映射(Conditional Mapping)
https://www.jianshu.com/p/8ed758ed3c63 条件映射(Conditional Mapping) AutoMapper 允许你给属性添加条件,只有在条件成立的情况下该成 ...
- HB-打包
一.文件打包 1.上传文件到根目录下 2.修更改启动文件 3.更改启动图标 四.启动图 https://www.yasuotu.com/size 480*762 720*1242 1080*1882
- 【转】Android编译系统详解(一)——build/envsetup.sh
出处 http://www.cloudchou.com/android/post-134.html 本文原创作者:Cloud Chou. 欢迎转载,请注明出处和本文链接 准备好编译环境后,编译Rom的 ...
- 016-zabbix低级自动发现以及MySQL多实例
1.概述 Zabbix的网络发现是指zabbix server通过配置好的规则,自动添加host,group,template Zabbix的主动注册刚好和网络发现是相反的,功能基本一致.zabbix ...
- 关于FileChannel的获取方式之open方法详解
FileChannel.open(Path path, OpenOption... options); 例子使用JDK1.8 FileChannel open方法源码: public static F ...
- 2018牛客网暑期ACM多校训练营(第十场)J Rikka with Nickname(二分,字符串)
链接:https://ac.nowcoder.com/acm/contest/148/J?&headNav=acm 来源:牛客网 Rikka with Nickname 时间限制:C/C++ ...
- small task
task:use c89 draw turtle result:
- oracle 创建表的规则
1.表明首字母 应该为字母 2.表名的最大长度为30个字符 3.不能使用oracle保留字和关键字来作表名 4.同一用户下的不同表不能具有相同的名称 5.可以使用下划线.数字和字母,但不能使用空格与单 ...
- Python之模块和包补充
包的补充 1.包A和包B下有同名模块也不会冲突,如A.a与B.a来自俩个命名空间 2.常见目录结构 1 import os 2 os.makedirs('glance/api') 3 os.maked ...