Doubt
Doubt

Reputation: 1222

Fixing axes ranges in pyplot subplots

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?

Upvotes: 2

Views: 2532

Answers (1)

Chris Zeh
Chris Zeh

Reputation: 924

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

Upvotes: 1

Related Questions