matplotlib

本文介绍了如何使用Python的numpy和matplotlib.pyplot库创建折线图、普通柱形图、推积柱形图以及包含误差棒的柱形图,展示了基本的数据可视化方法。
摘要由CSDN通过智能技术生成
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(4,19)
y_max = np.array([32,33,34,34,33,31,30,29,30,29,26,23,21,25,31])
y_min = np.array([19,19,20,22,22,21,22,16,18,18,17,14,15,16,16])
#绘制折线图
plt.plot(x, y_max)
plt.plot(x, y_min)
plt.show()

x = np.arange(5)
y1 = np.array([10,8,7,11,13])
y2 = np.array([9,6,5,10,12])
#柱形图的宽度
bar_width = 0.3
#根据多组数据绘制柱形图
plt.bar(x, y1, tick_label = ['a', 'b', 'c', 'd', 'e'], width=bar_width)
plt.bar(x+bar_width, y2, width=bar_width)
plt.show()

#绘制推积柱形图
plt.bar(x, y1, tick_label=['a', 'b', 'c', 'd', 'e'],width=bar_width)
plt.bar(x, y2, bottom=y1, width=bar_width)
plt.show()

#偏差数据
error = [2, 1, 2.5, 2, 1.5]
#绘制带有误差棒的柱形图
plt.bar(x, y1, tick_label = ['a', 'b', 'c', 'd', 'e'], width=bar_width)
plt.bar(x, y1, bottom=y1, width=bar_width, yerr=error)
plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值