簡體   English   中英

在Jupyter筆記本中縮放Matplotlib Plots的繪圖大小

[英]Scale plot size of Matplotlib Plots in Jupyter Notebooks

是否有可能在jupyter筆記本中縮放matplotlib圖的繪圖大小? 您可以通過更改figure.figsize的默認值來增加繪圖大小,但這不會影響fontsize,linewidth,markersize等參數。我需要的是一個繪圖,其中所有參數都相應縮放。

PS:要在jupyter筆記本中顯示圖,我使用%matplotlib inline ,請參見下面的截圖。

圖片

編輯

為了完整起見,這里有一個完全符合我需要的代碼片段:

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與圖形大小之間的關系

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM