欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python中利用规范化数据绘制直方图改变x轴刻度

程序员文章站 2022-05-27 16:02:18
...

利用规范化数据绘制直方图
python中利用规范化数据绘制直方图改变x轴刻度
代码如下:

import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['font.family'] = 'Microsoft YaHei'

interval = [0,5,10,15,20,25,30,35,40,45,60,90]
width = [5,5,5,5,5,5,5,5,5,15,30,60]
quantity = [836,2737,3723,3926,3596,1438,3273,642,824,613,215,47]

fig = plt.figure(figsize=(16,9),dpi=72)
ax1 = fig.add_subplot()
ax1.bar([x+0.5 for x in range(len(interval))], quantity, width=1)
ax1.set_xticks([x for x in range(len(interval))])
ax1.set_xticklabels(interval)
plt.show()

python中利用规范化数据绘制直方图改变x轴刻度

对x轴刻度标签进行调整

import matplotlib.pyplot as plt
fig=plt.figure(figsize=(16,9),dpi=80)
ax1=fig.add_subplot()
interval = [0,5,10,15,20,25,30,35,40,45,60,90]
width = [5,5,5,5,5,5,5,5,5,15,30,60]
quantity = [836,2737,3723,3926,3596,1438,3273,642,824,613,215,47]
ax1.bar([width[i]/2+x for i ,x in enumerate(interval)],quantity,width=width)
ax1.set_xticks([i for i in interval+[150]])
plt.show()

python中利用规范化数据绘制直方图改变x轴刻度

相关标签: 机器学习