[英]Scale plot size of Matplotlib Plots in Jupyter Notebooks
Is there a possibility to scale the plot size of matplotlib plots in jupyter notebooks? 是否有可能在jupyter笔记本中缩放matplotlib图的绘图大小? 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. 您可以通过更改figure.figsize
的默认值来增加绘图大小,但这不会影响fontsize,linewidth,markersize等参数。我需要的是一个绘图,其中所有参数都相应缩放。
PS: To display plots in jupyter notebooks I use %matplotlib inline
, see screenshot below. PS:要在jupyter笔记本中显示图,我使用%matplotlib inline
,请参见下面的截图。
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
You don't want to change the figure size. 您不想更改数字大小。 You want to change the dpi (dots per inch). 您想要更改dpi(每英寸点数)。
Also see Relationship between dpi and figure size . 另请参阅dpi与图形大小之间的关系 。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.