使用jupyter中的matplotlib库绘制简单图表

使用matplotlib库绘制图表最重要的就需要导入numpy模块和pyplot模块
1、绘制直线图`

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
data=np.array([3,5,7,9,11])
plt.plot(data)
plt.show()

在这里插入图片描述
2、绘制折线图

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
x=np.arange(4,19)
y_max=np.array([32,31,35,36,25,38,39,34,28,35,36,31,35,36,34])
plt.plot(x,y_max)
plt.show()

在这里插入图片描述

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
x=np.arange(4,19)
y_max=np.array([32,31,35,36,25,38,39,34,28,35,36,31,35,36,34])
y_min=np.array([19,15,21,35,26,15,18,24,18,27,27,29,16,25,14])
plt.plot(x,y_max)
plt.plot(x,y_min)
plt.show()

在这里插入图片描述
3、绘制柱形图
(1)

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
x1=np.arange(5)
y1=np.array([23,15,48,16,25])
bar_width=0.5
plt.bar(x1,y1,tick_label=['a','b','c','d','e'],width=bar_width)
plt.show()

在这里插入图片描述
(2)绘制多组柱形图

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
x1=np.arange(5)
y1=np.array([23,15,48,16,25])
y3=np.array([12,23,21,25,26])
bar_with=0.5
plt.bar(x1,y1,tick_label=['a','b','c','d','e'],width=bar_width)
plt.bar(x1+bar_width,y3,width=bar_width)
plt.show(

在这里插入图片描述
(3)绘制堆积柱形图

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
x1=np.arange(5)
y1=np.array([23,15,48,16,25])
y3=np.array([12,23,21,25,26])
plt.bar(x1,y1,tick_label=['a','b','c','d','e'],width=bar_width)
plt.bar(x1,y3,bottom=y2,width=bar_width)
plt.show()

在这里插入图片描述

(4)为堆积柱形图添加误差棒

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
x1=np.arange(5)
y1=np.array([23,15,48,16,25])
y3=np.array([12,23,21,25,26])
error=[2,1,2.5,2,1.5]
plt.bar(x1,y1,tick_label=['a','b','c','d','e'],width=bar_width)
plt.bar(x1,y3,bottom=y2,width=bar_width,yerr=error)
plt.show()

在这里插入图片描述
3、绘制条形图
(1)

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
yy=np.arange(5)
xx=np.array([23,15,48,16,25])
bar_height=0.5
plt.barh(yy,xx,tick_label=['a','b','c','d','e'],height=bar_height)
plt.show()

在这里插入图片描述
(2)绘制多组条形图

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
xx=np.array([23,15,48,16,25])
xx2=np.array([25,12,34,45,57])
yy=np.arange(5)
bar_height=0.5
plt.barh(yy,xx,tick_label=['a','b','c','d','e'],height=bar_height)
plt.barh(yy+bar_height,xx2,height=bar_height)
plt.show()

在这里插入图片描述
(3)绘制堆积条形图

plt.title("2020080603012")
import numpy as np
import matplotlib.pyplot as plt
xx2=np.array([25,12,34,45,57])
xx=np.array([23,15,48,16,25])
yy=np.arange(5)
bar_height=0.5
plt.barh(yy,xx,tick_label=['a','b','c','d','e'],height=bar_height)
plt.barh(yy,xx2,left=xx,height=bar_height)
plt.show()

在这里插入图片描述
(4)为堆积条形图添加误差棒

plt.title("2020080603012")
xx2=np.array([25,12,34,45,57])
xx=np.array([23,15,48,16,25])
yy=np.arange(5)
error=[2,1,2.5,2,1.5]
plt.barh(yy,xx,tick_label=['a','b','c','d','e'],height=bar_height)
plt.barh(yy,xx2,left=xx,height=bar_height,xerr=error)
plt.show()

在这里插入图片描述

  • 3
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值