如何增加python(matplotlib)中条形图的大小?

How to increase the size of bar graph in python (matplotlib)?

我正在尝试按以下方式绘制条形图:

# importing package
import matplotlib.pyplot as plt
import pandas as pd
  
# create data
df = pd.DataFrame([['A', 10, 20, 10, 30], ['B', 20, 25, 15, 25], ['C', 12, 15, 19, 6],
                   ['D', 10, 29, 13, 19]],
                  columns=['Team', 'Round 1', 'Round 2', 'Round 3', 'Round 4'])
# view data
print(df)
  
# plot grouped bar chart
df.plot(x='Team',
        kind='bar',
        stacked=False,
        title='Grouped Bar Graph with dataframe')

但是,条形图的尺寸非常小。为了使条形图的长度和宽度都更大,我应该做哪些更改?

可以使用宽度参数

df.plot(x='Team',
    kind='bar',
    stacked=False,
    title='Grouped Bar Graph with dataframe',
    width=0.5)
df.plot(x='Team',
        kind='bar',
        stacked=False,
        title='Grouped Bar Graph with dataframe',
        figsize = (10,10))

结果:(不舒服条形图)

要更改颜色图,请使用 colormap 参数。

from matplotlib import cm
...
df.plot(x='Team',
        kind='bar',
        stacked=False,
        title='Grouped Bar Graph with dataframe',
        figsize = (5,5),
        colormap = cm.get_cmap('Spectral') )

请参阅 pandas.plot 的文档。您要查找的参数是 figsize。 Pandas Plot Documentation