Dimensions of x and y are incompatible
![](https://secure.gravatar.com/avatar/368aaeee10436fc955dfb4a0a6ac6d50.jpg?s=120&d=mm&r=g)
Hi, I am trying to plot two curves on a same graph. The two input datasets are xdata, ydata and they range between (0.01, 1] for xdata and (0.1, 1] for ydata. I am constantly getting this error when plotting "Dimensions of x and y are incompatible" plt.figure() xdata= array(xd) ydata = array(xd) N=len(xdata) print "N: %d" % (N) x=arange(0.0, 1.0+0.01, 0.01) M=len(ydata) print "M: %d" % (M) y=arange(0.0, 1.0+0.1, 0.1) plt.plot(x,xdata,'r') plt.plot(y,ydata,'b') plot.legend((xl,yl)) plt.grid(True) plt.title(title) plt.xlabel('Value Ratio') plt.ylabel('Simulation Time Unit') pdf_name = '%s-%s.pdf' % (str(filename),strftime("%m%d-%M-%S")) pwd = os.getcwd() path = os.path.join(pwd, exp, pdf_name) plt.savefig(path) I have also tried: x=arange(1,N) y=arange(1,M) But it didn't work. Any help would be much appreciated. Thanks, Omer
![](https://secure.gravatar.com/avatar/764323a14e554c97ab74177e0bce51d4.jpg?s=120&d=mm&r=g)
On Mon, Aug 3, 2009 at 16:26, Omer Khalid<Omer.Khalid@cern.ch> wrote:
Hi,
I am trying to plot two curves on a same graph. The two input datasets are xdata, ydata and they range between (0.01, 1] for xdata and (0.1, 1] for ydata.
The matplotlib list is over here: https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
![](https://secure.gravatar.com/avatar/56b215661867f3b4f4a3b28077de66b3.jpg?s=120&d=mm&r=g)
On Aug 3, 2009, at 5:26 PM, Omer Khalid wrote:
Hi,
"Dimensions of x and y are incompatible" means what it means: you're trying to plot y (size 11) with x of size (110). That won't do: your x and y must have the same size (else, what happens to the extras x or y ?) Moreover, you may want to use np.linspace instead of np.arange for that: np.linspace(0,1,11) gives you 11 points regularly spaced between 0 and
Omer, You do realize this is the Scipy mailing list, right ? You should ask matplotlib related questions to the matplotlib mailing list: matplotlib-users@lists.sourceforge.net Anyhow: 1.
I am trying to plot two curves on a same graph. The two input datasets are xdata, ydata and they range between (0.01, 1] for xdata and (0.1, 1] for ydata.
I am constantly getting this error when plotting "Dimensions of x and y are incompatible"
plt.figure() xdata= array(xd) ydata = array(xd)
N=len(xdata) print "N: %d" % (N) x=arange(0.0, 1.0+0.01, 0.01) M=len(ydata) print "M: %d" % (M) y=arange(0.0, 1.0+0.1, 0.1) plt.plot(x,xdata,'r') plt.plot(y,ydata,'b') plot.legend((xl,yl)) plt.grid(True) plt.title(title) plt.xlabel('Value Ratio') plt.ylabel('Simulation Time Unit') pdf_name = '%s-%s.pdf' % (str(filename),strftime("%m %d-%M-%S")) pwd = os.getcwd() path = os.path.join(pwd, exp, pdf_name) plt.savefig(path)
I have also tried: x=arange(1,N) y=arange(1,M)
But it didn't work. Any help would be much appreciated.
Thanks, Omer
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
![](https://secure.gravatar.com/avatar/f0e14e3d3fedba744ede17396d394c73.jpg?s=120&d=mm&r=g)
2009/8/3 Omer Khalid <Omer.Khalid@cern.ch>: I am constantly getting this error when plotting "Dimensions of x and y are incompatible"
The x and y here are refering to the values of the parameters inside the plt.plot() function, *not* out in your code, so it's a bit confusing...
plt.figure() xdata= array(xd) ydata = array(xd)
The first problem is that you haven't told us how big your xd is..
N=len(xdata) print "N: %d" % (N) x=arange(0.0, 1.0+0.01, 0.01)
Unless you're lucky, your x probably doesn't have length N
M=len(ydata) print "M: %d" % (M) y=arange(0.0, 1.0+0.1, 0.1)
Again, y probably doesn't have length M (which equals N..)
plt.plot(x,xdata,'r')
So (unless you're lucky) the call above will fail because x and xdata don't have the same length.
plt.plot(y,ydata,'b')
If you were lucky before, the call above will certainly fail because y does not have the same length as ydata, x or xdata.
But it didn't work. Any help would be much appreciated.
I hope you've managed to work it out now :) Cheers, Scott
participants (4)
-
Omer Khalid
-
Pierre GM
-
Robert Kern
-
Scott Sinclair