Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python equivalent to 'hold on' in Matlab

Is there an explicit equivalent command in Python's matplotlib for Matlab's hold on? I'm trying to plot all my graphs on the same axes. Some graphs are generated inside a for loop, and these are plotted separately from su and sl:

import numpy as np import matplotlib.pyplot as plt  for i in np.arange(1,5):     z = 68 + 4 * np.random.randn(50)     zm = np.cumsum(z) / range(1,len(z)+1)     plt.plot(zm)     plt.axis([0,50,60,80])  plt.show()  n = np.arange(1,51) su = 68 + 4 / np.sqrt(n) sl = 68 - 4 / np.sqrt(n)  plt.plot(n,su,n,sl)  plt.axis([0,50,60,80]) plt.show() 
like image 479
Medulla Oblongata Avatar asked Jan 30 '14 19:01

Medulla Oblongata


People also ask

Is there a hold on in Python?

The hold on feature is switched on by default in matplotlib. pyplot . So each time you evoke plt. plot() before plt.

What does PLT pause do in Python?

The pause() function in pyplot module of matplotlib library is used to pause for interval seconds. Parameters: This method does not accepts any parameters.


2 Answers

Just call plt.show() at the end:

import numpy as np import matplotlib.pyplot as plt  plt.axis([0,50,60,80]) for i in np.arange(1,5):     z = 68 + 4 * np.random.randn(50)     zm = np.cumsum(z) / range(1,len(z)+1)     plt.plot(zm)      n = np.arange(1,51) su = 68 + 4 / np.sqrt(n) sl = 68 - 4 / np.sqrt(n)  plt.plot(n,su,n,sl)  plt.show() 
like image 171
Alvaro Fuentes Avatar answered Oct 06 '22 07:10

Alvaro Fuentes


You can use the following:

plt.hold(True) 
like image 41
mapsa Avatar answered Oct 06 '22 06:10

mapsa