I want to create a function that would return a pyplot
object but will not plot it out unless explicitly specified.
Following is a example function similar to what I'm trying to create.
import numpy as np
import matplotlib.pyplot as plt
def plot_it_now():
A = np.linspace(0,10,10)
B = np.exp(A)
fig = plt.figure()
plt.plot(A, label='linear sequence')
plt.plot(B, label='exponential sequence')
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.legend(loc='best')
myplot = plot_it_now()
the problem is the moment I call this function into a variable it also plots it out. While that's the usual behaviour, I want to persist the pyplot object into a variable and it should plot it only when i call it. Something like this,
plt.figure(figsize=(5,5))
myplot = plot_it_now()
plt.show()