Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pandas和Matplotlib-如何更改绘图区域以适应更多的x轴文本?_Python_Numpy_Matplotlib_Pandas_Graphing - Fatal编程技术网

Python Pandas和Matplotlib-如何更改绘图区域以适应更多的x轴文本?

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()

假设我将此csv文件读入熊猫数据框:

文件内容:

代码:

给出:

然后使用
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')