繁体   English   中英

Matplotlib条形图轴值

[英]Matplotlib bar graph axes values

我想要一个条形图,显示x值,范围从0-9。 条形图应具有相同的空间,而我遇到的问题是将10个值拟合在一起,而所有条形图具有相同的面积。

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(10, 6))
results_plot = plt.subplot2grid((10, 6), (0,0), colspan=8, rowspan=2)
results_plot.set_title("Results")

res_x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
res_y = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

rects = plt.bar(res_x, res_y, color='b')
results_plot.set_xbound(lower=0.0, upper=9.0)
results_plot.set_ybound(lower=0.0, upper=100.0)


results_plot2 = plt.subplot2grid((10, 6), (3,0), colspan=8, rowspan=2)
results_plot2.set_title("Results 2")

res_x2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
res_y2 = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

rects2 = plt.bar(res_x2, res_y2, color='b')
results_plot2.set_xbound(lower=-.5, upper=9.5)
results_plot2.set_ybound(lower=0.0, upper=100.0)

plt.show()

在此处输入图片说明

简而言之,我想查看轴上的所有x值(如图1所示),每个值都具有相同的条形空间(图2)。

如果您只想在每个小节的下方打勾,则可以使用xticks直接设置res_x 加:

results_plot2.set_xticks(res_x)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM