Python Pandas和Matplotlib-如何更改绘图区域以适应更多的x轴文本?
假设我将此csv文件读入熊猫数据框: 文件内容: 代码: 给出: 然后使用Python Pandas和Matplotlib-如何更改绘图区域以适应更多的x轴文本?,python,numpy,matplotlib,pandas,graphing,Python,Numpy,Matplotlib,Pandas,Graphing,假设我将此csv文件读入熊猫数据框: 文件内容: 代码: 给出: 然后使用groupby对字符串求和: g=c.groupby(u'Strings').sum() 给予: 最后,这样画: g.plot(kind='bar') 给予: 正如您所看到的,x轴文本被严重裁剪。我怎样才能解决这个问题 请注意,我已尝试使用rot参数(例如rot=-45),但这是不够的 我想解决方案可能包括设置绘图区域,但我不确定如何做到这一点。您是否尝试过:plt.tight_layout()
groupby
对字符串求和:
g=c.groupby(u'Strings').sum()
给予:
最后,这样画:
g.plot(kind='bar')
给予:
正如您所看到的,x轴文本被严重裁剪。我怎样才能解决这个问题
请注意,我已尝试使用rot
参数(例如rot=-45
),但这是不够的
我想解决方案可能包括设置绘图区域,但我不确定如何做到这一点。您是否尝试过:plt.tight_layout()
Strings Values Letters
0 Made up data 55.0 A
1 with long text strings for index 125.5 B
2 with long text strings for index 85.5 B
3 how does one 1.3 A
4 how does one 12.3 A
5 change the plot area to 96.1 B
6 fit all of this text in? 0.2 B
7 fit all of this text in? 47.2 B
g=c.groupby(u'Strings').sum()
Values
Strings
Made up data 55.0
change the plot area to 96.1
fit all of this text in? 47.4
how does one 13.6
with long text strings for index 211.0
g.plot(kind='bar')