-1

I want to give all the figures in my code a single title #Variable_cycles. Figures are not subplots but plotted separately. I am using %matplotlib to show plots in separate window. As far as i know plt.rcParams has no such key

import matplotlib.pyplot as plt

%matplotlib

plt.figure(1), plt.scatter(x,y,marker='o'),
plt.title("Variable_cycles"),
plt.show

plt.figure(2),
plt.scatter(x,y,marker='*'),
plt.title("Variable_cycles"),
plt.show
tmdavison
  • 64,360
  • 12
  • 187
  • 165

1 Answers1

0

I don't believe there is such a setting in rcParams or similar, but if there are options you are setting for all figures, you could create a simple helper function to create the figure, apply those settings (e.g. the title, axes labels, etc), and return the figure object, then you just need to call that function once for each new figure. A simple example would be:

import matplotlib.pyplot as plt

%matplotlib

def makefigure():
    
    # Create figure and axes
    fig, ax = plt.subplots()
    
    # Set title
    fig.suptitle('Variable cycles')

    # Set axes labels
    ax.set_xlabel('My xlabel')
    ax.set_ylabel('My ylabel')

    # Put any other common settings here...

    return fig, ax

fig1, ax1 = makefigure()
ax1.scatter(x, y, marker='o')           

fig2, ax2 = makefigure()
ax2.scatter(x, y, marker='*')
   
tmdavison
  • 64,360
  • 12
  • 187
  • 165