I know how to set figure size and DPI of one plot by fig, ax = plt.figure(figsize=(8,8), dpi=140)
.
But I am wondering there is a way that can change the figure size or DPI of all plots without specifying these values each time.
Could anyone help me?
Thanks in advance.
If not provided, defaults to rcParams["figure. figsize"] = [6.4, 4.8] .
resolution of the figure. If not provided, defaults to rcParams["figure. dpi"] (default: 100.0) = 100 .
For your specific case, you probably want to set
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [8.0, 8.0]
plt.rcParams['figure.dpi'] = 140
This will change the default for this one script.
However, there are a number of ways how you can change the defaults permanently. You could modify the matplotlibrc
file or create your own style sheet. Please refer to the matplotlib documentation for details:
1. Apply to a single file
import matplotlib.pyplot as plt
plt.rcParams['savefig.dpi'] = 300
%matplotlib inline
2. Apply to all files
Find ~\Python37\Lib\site-packages\matplotlib\mpl-data\matplotlibrc
. Let figure.dpi=300
.
This will be overwritten in your next install. Put this file in the following path can avoid being overwritten.
$HOME/.config/matplotlib/matplotlibrc
$XDG_CONFIG_HOME/matplotlib/matplotlibrc
$HOME/.matplotlib/matplotlibrc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With