Hello, I've run into a strange behaviour of matplotlib while trying to figure out why my data was displayed incorrectly. I'm note quite sure if this is a bug or expected behaviour, but I feel it's kind of counter-intuitive, so I'm posting here.
The attached python script does a scatter plot of some data. I'm using the first column as the x coordinates and the second as y. Looking at the matrix (x == y), I'd expect the three data point to be on a diagonal line. Now there seem to be a difference on how numpy handles A[:,0] depending on if A is a np.array or np.matrix. In the case of an array, a 1D array is returned, in the case of a matrix, a 2D Nx1 matrix is returned. Using this matrix seems to confuse matplotlib. Using np.ravel or np.flatten on the slices fix that problem. Is there an explanation for this behaviour or should I fill a bug ? Best regards, Julien Rebetez
<<attachment: matrix_plot.png>>
import pylab as pl import numpy as np A = np.array([[1, 1], [2, 2], [3, 3]]) B = np.matrix(A) # As far as I understand, the problem seems to be caused by the fact that one # is a 1D array and the other a 2D array (with only one column) print A[:,1].shape print B[:,1].shape pl.figure() pl.scatter(A[:,0], A[:,1], c='r') pl.scatter(B[:,0], B[:,1], c='b') pl.show()
------------------------------------------------------------------------------ This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users