简体   繁体   English

在Jupyter笔记本中缩放Matplotlib Plots的绘图大小

[英]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 ,请参见下面的截图。

图片

Edit 编辑

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.

相关问题 Qubole Notebook 中 matplotlib 图的比例图大小 - Scale plot size of matplotlib plots in Qubole Notebook Matplotlib和Jupyter Notebooks:每个循环迭代输出新图 - Matplotlib and Jupyter Notebooks: new plot outputted per loop iteration 如何在matplotlib图中更改比例的字体大小? - How do I change the font size of the scale in matplotlib plots? 使用魔法时看不到在 Jupyter 笔记本中创建的 plot:%matplotlib 笔记本。 Windows 10 和铬 - Not possible to see the plot created in Jupyter notebooks when using magic: %matplotlib notebook. Windows 10 and Chrome 调整图中的y-lim比例(matplotlib,pandas)以实现两个图的相同比例 - Adjusting y-lim Scale in the Plot (matplotlib, pandas) to Achieve Same Scale for Both Plots 如何在 Jupyter 笔记本中将 matplotlib 输出居中? - How to center matplotlib outputs in Jupyter notebooks? Jupyter Notebooks 使用 Matplotlib 打印出波浪形的扭曲图形 - Jupyter Notebooks prints a wavy, distorted graph with Matplotlib MATPLOTLIB-增加地块的规模 - MATPLOTLIB - Increase scale for plot Plot 在一个图两个独立的地块上,带有 matplotlib,x 和 y 上的比例不同 - Plot on one fig two independent plots with matplotlib, different scale on x and y jupyter notebooks 中的绘图:保存时验证失败 - plotly plots in jupyter notebooks: Validation fails when saving
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM