I'm trying to add a second x-axis to the plot generated by the script below. The plot is continuously being updated:
import numpy as np
import matplotlib.pyplot as plt
#turn interactive mode on
plt.ion()
def GetTestData():
data = []
for i in range(0, 2048):
data.append(np.random.random_sample() * i)
return data
for i in range(0, 100):
plt.clf()
plt.plot(GetTestData())
plt.show()
plt.pause(0.05)
I found this Stack Overflow solution on how to add an extra axis, but when I tried using the solution in my script, I get many plots instead of refreshing a single one:
import numpy as np
import matplotlib.pyplot as plt
#turn interactive mode on
plt.ion()
def GetTestData():
data = []
for i in range(0, 2048):
data.append(np.random.random_sample() * i)
return data
for i in range(0, 100):
plt.clf()
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
ax1.plot(GetTestData())
ax2.plot(range(100), np.ones(100)) # Create a dummy plot
ax2.cla()
plt.show()
plt.pause(0.05)
Any help would be appreciated