问题描述
是否有可能在jupyter笔记本中缩放matplotlib图的图大小?您可以通过更改默认值figure.figsize
来增加绘图大小,但这不会影响诸如字体大小,线宽,标记大小等参数.我需要的是一个绘图,其中所有参数均按比例缩放.
Is there a possibility to scale the plot size of matplotlib plots in jupyter notebooks? You could increase the plot size by changing the default values of figure.figsize
, but this does not affect parameters like fontsize, linewidth, markersize etc. What I need is a plot where all the parameters are scaled accordingly.
P.S .:要在Jupyter笔记本中显示情节,请使用%matplotlib inline
,请参见下面的屏幕截图.
P.S.: To display plots in jupyter notebooks I use %matplotlib inline
, see screenshot below.
为完整起见,以下代码片段完全满足我的需要:
For completeness, here is a code snippet doing exactly what I needed:
def scale_plot_size(factor=1.5):
import matplotlib as mpl
default_dpi = mpl.rcParamsDefault['figure.dpi']
mpl.rcParams['figure.dpi'] = default_dpi*factor
推荐答案
您不想更改图形尺寸.您要更改dpi(每英寸的点数).
另请参见 dpi与图形尺寸之间的关系
You don't want to change the figure size. You want to change the dpi (dots per inch).
Also see Relationship between dpi and figure size.
import matplotlib.pyplot as plt
%matplotlib inline
def plot(dpi):
fig, ax=plt.subplots(dpi=dpi)
ax.plot([2,4,1,5], label="Label")
ax.legend()
for i in range(1,4):
plot(i*72)
这篇关于Jupyter笔记本中Matplotlib图的比例图大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!