[英]How to increase the size of bar graph in python (matplotlib)?
I am am trying to plot a bar graph in the following manner:我正在尝试通过以下方式 plot 条形图:
# 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')
However, the size of the bar graph is very small.但是,条形图的尺寸非常小。 What changes should I make in order to make the bar graph bigger both in length and breadth?
为了使条形图的长度和宽度都变大,我应该做哪些更改?
You can use the width parameter您可以使用宽度参数
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))
Result: ( Uncomfortably big bar plot)结果:(令人不舒服的大条形图)
For changing the colormap use the colormap
parameter.要更改颜色图,请使用
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') )
See the documentation for pandas.plot.请参阅 pandas.plot 的文档。 The parameter you are looking for is figsize.
您要查找的参数是 figsize。 Pandas Plot Documentation
Pandas Plot 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.