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(‘人数’). 注 ...
随机推荐
- POJ 2955 Brackets 区间DP 入门
dp[i][j]代表i->j区间内最多的合法括号数 if(s[i]=='('&&s[j]==')'||s[i]=='['&&s[j]==']') dp[i][j] ...
- hibernate update-->参数绑定
Hibernate 更新数据库 参数绑定总结: 一.query.setParameter(属性名,真实值,类型); String hql="update User u set u.userN ...
- python 压缩文件(解决压缩路径问题)
#压缩文件 def Zip_files(): datapath = filepath # 证据路径 file_newname = datapath + '.zip' # 压缩文件的名字 log.deb ...
- 对比XGBoost与深度学习
观点1:XGBoost要比深度学习更重要.2016年Kaggle大赛29个获奖方案中,17个用了XGBoost.因为它好用,在很多情况下都更为可靠.灵活,而且准确:在绝大多数的回归和分类问题上,XGB ...
- Codeforces 10D LCIS 求最长公共上升子序列及输出这个子序列 dp
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qq574857122/article/details/34430283 题目链接:点击打开链接 题意 ...
- node.js使用express模块创建web服务器应用
1.安装express模块 在命令行输入 npm install body-parser --save npm install express --save 2.创建app.js文件 /*应用程序入口 ...
- vue - helloVue
开始学习vue了 1.数据绑定:{{data}} 2.el属性(挂载对象): el:标签任意(例如:#app,.app,app) 3.data:{} :存放数据. <!DOCTYPE html& ...
- module.exports exports npm --save
CommonJS模块规范和ES6模块规范完全是两种不同的概念 Node应用由模块组成,采用CommonJS模块规范 var x = 5; var addX = function (value) { r ...
- python2 'ascii'编码问题
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 223: ordinal not in range(128) ...
- VMware主机使用无线上网
VMware主机使用无线上网,默认的NAT连接在ubuntu下上不了网,需要把网络适配器改成桥接模式.