python matplotlib 绘制柱状图
"""
绘制柱状图
"""
import numpy
as np
import matplotlib
.pyplot
as mp
mp
.rcParams
['font.sans-serif'] = ['SimHei']
mp
.rcParams
['axes.unicode_minus'] = False
apples
= np
.random
.randint
(10, 100, 12)
oranges
= np
.random
.randint
(10, 100, 12)
mp
.figure
("Bar", facecolor
="lightgray", figsize
=(10, 6))
mp
.title
("Bar", fontsize
=18)
mp
.xlabel
('月份', fontsize
=14)
mp
.ylabel
('价格', fontsize
=14)
mp
.tick_params
(labelsize
=10)
x
= np
.arange
(len(apples
))
mp
.bar
(x
- 0.2, apples
, 0.4, align
="center", label
="Apples")
mp
.bar
(x
+ 0.2, oranges
, 0.4, align
="center", label
="Oranges")
mp
.grid
(axis
="y", linestyle
=":")
mp
.xticks
(x
, ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"])
mp
.legend
()
mp
.show
()
转载请注明原文地址:https://ipadbbs.8miu.com/read-26251.html