如何在 matplotlib 和 pandas 中增加图像大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31611463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 23:40:44  来源:igfitidea点击:

How to increase image size in matplotlib and pandas?

pythonpandasmatplotlib

提问by Blue Moon

I am trying to increase the size of the image resulting from this function:

我正在尝试增加此功能产生的图像的大小:

plt.figure()); data_ordertotal.plot(); plt.legend(loc='best')

I tried this but the size remains the same

我试过了,但大小保持不变

plt.figure(figsize=(40,40)); data_ordertotal.plot(); plt.legend(loc='best')

I am coding using spyder and the output in the console remains always the same size. Any solution? Thanks

我正在使用 spyder 进行编码,并且控制台中的输出始终保持相同的大小。有什么解决办法吗?谢谢

回答by jrjc

I guess you're using pandas, and you should use:

我猜你正在使用Pandas,你应该使用:

data_ordertotal.plot(figsize=(40,40))

It doesn't work with plt.figure(figsize=(40,40))because pandas will create a new figure if you don't pass it an axeobject.

它不起作用,plt.figure(figsize=(40,40))因为如果您不将axe对象传递给Pandas,它会创建一个新图形。

It would work with:

它将与:

fig, ax = plt.subplots(1, 1, figsize=(40,40))
data_ordertotal.plot(ax=ax)

...Assuming you're using pandas, if not you should detail a bit more what is data_ordertotal

...假设您使用的是Pandas,如果不是,您应该详细说明一下是什么 data_ordertotal

HTH

HTH

回答by kaminsknator

when you create a figure change the figsize. The dimension are in inches

创建图形时,请更改图形大小。尺寸单位为英寸

import matplotlib.pyplot as plt

plt.figure(num=1, figsize=(40, 40), dpi=80, facecolor='w', edgecolor='k')

That works for me in spyder.

这在 spyder 中对我有用。

fig = plt.gcf()
fig.set_size_inches(18.5, 10.5)

should also work

也应该工作