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(‘人数’). 注 ...
随机推荐
- <<C++ Primer>> 第四章 表达式
术语表 第 4 章 表达式 算术转换(arithmetic conversion): 从一种算术类型转换成另一种算术类型.在二元运算符的上下文中,为了保留精度,算术转换通常把较小的类型转换成较大的类型 ...
- Linux免密登陆设置了免密登陆为啥还需要输入密码
一.设置了免密码登陆但是还是需要输入密码: 权限保证:1.authorized-keys 的权限为 600 2.home.账户所在的目录如hadoop..ssh这三个文件的权限都必须设置为700,缺少 ...
- python 路径操作工具 pathlib,比 os 模块好用太多
在 python 当中,如果你想控制路径,基本上绕不开 os.path.我希望看完这篇文章以后,熟练使用 python 的你能立刻开始使用 pathlib 模块,一刻也不要耽误. pathlib 相对 ...
- jackson json序列化 首字母大写 第二个字母需小写
有这样一个类: @Setter @Getter @JsonNaming(value = PropertyNamingStrategy.UpperCamelCaseStrategy.class) pub ...
- centos:mysql主从同步配置(2018)
centos:mysql主从同步配置(2018) https://blog.csdn.net/liubo_2016/article/details/82379115 主服务器:10.1.1.144; ...
- [转载]Linux查看文件编码格式及文件编码转换
原文地址:https://blog.csdn.net/gatieme/article/details/55045883 3 linux下查看编码的方法 方法一:file filename file c ...
- 六、while循环
案例1: do while 循环 很少用到. for循环和while循环用的最多.
- api接口统一封装
具体的接口api模块,例如authorization.js import axios from '../axiosWrapper' let prefix = process.env.API_ROOT ...
- Spring Boot任务(定时,异步,邮件)
一.定时任务 开启定时任务(在Spring Boot项目主程序上添加如下注解) @EnableScheduling //开启定时任务的注解 创建定时任务(创建一个Service如下) @Service ...
- SSL交互简述及nginx双向认证配置
一.证书生成. 1.SSL Server生成私钥/公钥对.server.key(加密)/server.pub(解密):2.server.pub生成请求文件server.csr,包含server的一些信 ...