I am writing a plotting function in python
using matplotlib
. The user can specify some things, e.g. "tick lines". The easiest way would be to change the rcParams
, but those are global properties, so all new plots will have tick lines after that plotting function was called.
Is there a way to set the plotting defaults specifically for just one figure?
Or is there at least a good way to change the properties for one plotting-function and then change them back to the values that were used before (not necessarily the rcdefaults
)?
Use matplotlib. style. use('default') or rcdefaults() to restore the default rcParams after changes.
Hence, to set a single main title for all subplots, suptitle() method is used. Parameters: This method accept the following parameters that are discussed below: t : This parameter is the title text.
matplotlib.rc can be used to modify multiple settings in a single group at once, using keyword arguments: mpl. rc('lines', linewidth=4, linestyle='-.') plt.
It stands for “run commands”.
You can use the rc_context
function in a with
statement, which will set the rc parameters with a dictionary you provide for the block indented below and then reset them to whatever they were before after the block. For example:
with plt.rc_context({"axes.grid": True, "grid.linewidth": 0.75}):
f, ax = plt.subplots() # Will make a figure with a grid
ax.plot(x, y)
f, ax = plt.subplots() # Will make a figure without a grid
ax.plot(x, y)
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