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.
Asked
Active
Viewed 2.3k times
20

Bowen Peng
- 1,635
- 4
- 21
- 39
-
Possible duplicate of [How do you change the size of figures drawn with matplotlib?](https://stackoverflow.com/questions/332289/how-do-you-change-the-size-of-figures-drawn-with-matplotlib) – Andras Deak -- Слава Україні May 21 '19 at 06:57
2 Answers
35
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:

Jason R Stevens CFA
- 2,232
- 1
- 22
- 28

pktl2k
- 598
- 5
- 12
4
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.
- Unix/Linux:
$HOME/.config/matplotlib/matplotlibrc
$XDG_CONFIG_HOME/matplotlib/matplotlibrc
- Other platforms:
$HOME/.matplotlib/matplotlibrc

W. Ding
- 587
- 4
- 15