Python 如何使 Jupyter Notebook 中的内联图更大?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36367986/
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
How to make inline plots in Jupyter Notebook larger?
提问by Christopher
I have made my plots inline on my Ipython Notebook with "%matplotlib inline
."
我已经在我的 Ipython Notebook 上使用“ %matplotlib inline
.”将我的绘图内联。
Now, the plot appears. However, it is very small. Is there a way to make it appear larger using either notebook settings or plot settings?
现在,剧情出现了。但是,它非常小。有没有办法使用笔记本设置或绘图设置使它看起来更大?
采纳答案by roadrunner66
Yes, play with figuresize
like so (before you call your subplot):
是的,figuresize
像这样玩(在你调用你的子图之前):
fig=plt.figure(figsize=(18, 16), dpi= 80, facecolor='w', edgecolor='k')
回答by tacaswell
The default figure size (in inches) is controlled by
默认图形大小(以英寸为单位)由控制
matplotlib.rcParams['figure.figsize'] = [width, height]
For example:
例如:
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [10, 5]
creates a figure with 10 (width) x 5 (height) inches
创建一个 10(宽)x 5(高)英寸的图形
回答by SlimCheney
I have found that %matplotlib notebook
works better for me than inline with Jupyter notebooks.
我发现这%matplotlib notebook
比内联 Jupyter 笔记本更适合我。
Note that you may need to restart the kernel if you were using %matplotlib inline
before.
请注意,如果您%matplotlib inline
之前使用过,则可能需要重新启动内核。
Update 2019:
If you are running Jupyter Lab you might want to use
%matplotlib widget
2019 年更新:如果您正在运行 Jupyter Lab,您可能想要使用
%matplotlib widget
回答by Hagne
If you only want the image of your figure to appear larger without changing the general appearance of your figure increase the figure resolution. Changing the figure size as suggested in most other answers will change the appearance since font sizes do not scale accordingly.
如果您只想让您的图形图像看起来更大而不改变图形的整体外观,请增加图形分辨率。按照大多数其他答案中的建议更改图形大小会改变外观,因为字体大小不会相应地缩放。
import matplotlib.pylab as plt
plt.rcParams['figure.dpi'] = 200
回答by Jared Wilber
The question is about matplotlib
, but for the sake of any R users that end up here given the language-agnostic title:
问题是关于matplotlib
,但是为了任何最终到达这里的 R 用户考虑到与语言无关的标题:
If you're using an R kernel, just use:
如果您使用的是 R 内核,只需使用:
options(repr.plot.width=4, repr.plot.height=3)
回答by farrellw
To adjust the size of one figure:
要调整一个图形的大小:
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(15, 15))
To change the default settings, and therefore all your plots:
要更改默认设置,从而更改所有绘图:
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [15, 15]
回答by RGood
A small but important detail for adjusting figure size on a one-off basis (as several commenters above reported "this doesn't work for me"):
一次性调整图形大小的一个小而重要的细节(如上面的几位评论者报告的“这对我不起作用”):
You should do plt.figure(figsize=(,)) PRIOR to defining your actual plot. For example:
你应该在定义你的实际情节之前做 plt.figure(figsize=(,)) 。例如:
This should correctly size the plot according to your specified figsize:
这应该根据您指定的 figsize 正确调整图的大小:
values = [1,1,1,2,2,3]
_ = plt.figure(figsize=(10,6))
_ = plt.hist(values,bins=3)
plt.show()
Whereas this will show the plot with the default settings, seeming to "ignore" figsize:
而这将显示默认设置的情节,似乎“忽略”figsize:
values = [1,1,1,2,2,3]
_ = plt.hist(values,bins=3)
_ = plt.figure(figsize=(10,6))
plt.show()