如何调整使用matplotlib创建的条形图的大小



我发现了其他类似的主题,但我发现了任何适合我的主题,所以我想知道我做错了什么。

我有以下代码:

# Plot weather vs. # of accidents on grouped-bar-chart for each year
data_chart = dataset2.plot.bar()
data_chart.set_xlabel('Weather Condition')
data_chart.set_ylabel('No. of Accidents')
data_chart.set_title('Annual Number of Accidents per Weather Condition')

我尝试使用以下两个代码来增加图表的大小:

data_chart.plot(figsize=(10,5))
plt.figure(figsize=[10,5])

但它们都没有起作用。

谢谢你的帮助!

请尝试

import matplotlib .pyplot as plt
plt.rcParams["figure.figsize"] = (10,5)
data_chart = dataset2.plot.bar()
data_chart.set_xlabel('Weather Condition')
data_chart.set_ylabel('No. of Accidents')
data_chart.set_title('Annual Number of Accidents per Weather Condition')
plt.show()

Matplot库默认为**to width, height in inches=[6.4, 4.8]**。设置为CCD_ 2。所以将它们更改为(10,5)

最新更新