Question

I am trying to plot data sets U(x,t) and V(x,t) using Python's matplotlib.pyplot subplots. I want to manually set the axes of the first subplot, while the second subplot can choose its own axis:

import matplotlib.pyplot as plt

plt.subplot(121)
plt.pcolor(xx,tt,U)
plt.colorbar()
plt.axes([0,600,0,100])
plt.subplot(122)
plt.pcolor(xx,tt,V)
plt.colorbar()
plt.show()

However, this seems to have no effect on changing the axes of the first subplot. Also, after the plot generates, I get an extensive error:

Exception in Tkinter callback
...
...
raise LinAlgError('Singular matrix')
numpy.linalg.linalg.LinAlgError: Singular matrix

When I remove the above plotting commands from my code, however, the error disappears. Any thoughts?

Was it helpful?

Solution

Instead of trying to set the axes itself, you can try adjusting the xlim and ylim properties instead:

import matplotlib.pyplot as plt
from numpy import *
xx = arange(0,700,30)
tt = arange(0,100,5)
U = outer(xx,tt)
V = outer(xx**(1/2),tt/4)
plt.subplot(121)
plt.pcolor(tt,xx,U)
plt.colorbar()
#plt.axes([0,600,0,100])

plt.xlim(0,100)
plt.ylim(0,600)

plt.subplot(122)
plt.pcolor(tt,xx,V)
plt.colorbar()

plt.show()

Script Output

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top