2

I am doing some experimentations with plotting and I like big plots i.e plots on a big picture. So I have to manually do

plt.figure(figsize=(15,8))
myplotcode

every time. I want to know is there anyway that I set this figsize as constant in starting and do not use it manaully everytime.

Thanks

0

2 Answers 2

3

In MatplotLib to can edit the base parameters, which is arranged in a dict form. You can actually change every default parameter. In your case it would like this:

rcParams["figure.figsize"] = [15, 8]

For more parameters you can change, you can check out the documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

@ipj only until the process exits
2

If you want to set the figure size once and forever you can store you preferences (not only the figure size) in an initialization file, named matplotlibrc

On linux/Unix like systems

$ mkdirhier ~/.config/matplotlib
$ echo "figure.figsize     : 10, 7" >> /home/boffi/.config/matplotlib/matplotlibrc
$ python
...
>>> import matplotlib.pyplot
>>> matplotlib.pyplot.figure()
<Figure size 1000x700 with 0 Axes> 
>>> # the above size is in pixels, at the default of 100 dpi
>>> 

To know the location of the configuration directory you can do

$ python
...
>>> import matplotlib
>>> matplotlib.get_configdir()
'/home/user1001/.config/matplotlib'
>>> 

An initialization file is good for you, but if you want to distribute your script to other people, with different initialization files, well it's no more so good!

A possible remedy is to go with Matplotlib's style sheets that allows you to load all of your tweakings with a single statement

plt.style.use('./mystyle.mplstyle')

and also the possibility of using a style as a context manager

plt.plot(...)         # default style
with plt.style.context('./mystyle.mplstyle'):
     plt.plot(...)    # your style

so that you can distribute your style sheet along with your script and your user will not be affected by a global modification of the defaults.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.