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(‘人数’). 注 ...
随机推荐
- 初识JavaScript(三)
初识JavaScript(三) 我从上一讲<初识JavaScript(二)>了解到了类型.值.变量的定义以及特点,本节我将学习到JavaScript中的算术运算.二进制浮点数和四舍五入的错 ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- C语言中将二维数组作为函数参数来传递
c语言中经常需要通过函数传递二维数组,有三种方法可以实现,如下: 方法一, 形参给出第二维的长度. 例如: #include <stdio.h> void func(int n, char ...
- 别人的Linux私房菜(24-25)X Window设置介绍、Linux内核编译与管理
X Window主要组件为:X Server .X Client . Window Manager . Display Manager. X Server管理硬件,X Client则为应用程序,将所需 ...
- 在.NET Core 3.0中发布单个Exe文件(PublishSingleFile)
原文:在.NET Core 3.0中发布单个Exe文件(PublishSingleFile) 假设我有一个简单的" Hello World"控制台应用程序,我想发送给朋友来运行.朋 ...
- 查看ftp创建的用户
先su然后查看cat /etc/passwd,500以后的是添加的使用者账户.
- Linux FTP的安装与权限配置
ftp安装部分,操作步骤如下: 1.切换到root用户 2.查看是否安装vsftp,我这个是已经安装的. [root@localhost vsftpd]# rpm -qa |grep vsftpd v ...
- HMC版本支持
Target Version Upgrade From Upgrade Instructions Updates Date Available End of Service Models supp ...
- html-DOM了解
什么是 HTML DOM? HTML DOM 是: HTML 的标准对象模型 HTML 的标准编程接口 W3C 标准 HTML DOM 定义了所有 HTML 元素的对象和属性,以及访问它们的方法. 换 ...
- PCRE does not support \L, \l, \N{name}, \U, or \u...
PCRE does not support \L, \l, \N{name}, \U, or \u... 参考文章:YCSUNNYLIFE 的 <php 正则匹配中文> 一.报错情景: 使 ...