JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
476 stars 87 forks source link

Accept both row and column vectors in plot() #101

Open dcarrera opened 9 years ago

dcarrera commented 9 years ago

It would be nice if the plot() command could accept row vectors as well as column vectors. As it is now, this code doesn't work:

julia> x = [1 2 3 4];
julia> y = [2 3 5 8];
julia> plot(x,y)

The reason is that Matplotlib is finicky about accepting row vectors vs column vectors. This is a needless limitation in Matplotlib that prevents some simple examples from working correctly. To get around this limitation, PyPlot could/should transpose the vectors as needed before giving them to Matplotlib. It is an easy fix that would make the PyPlot more useful.

stevengj commented 9 years ago

The only problem I see is that in principle you have an ambiguity here: I could interpret your commands above as plotting four data sets (four columns), each of which consists of only a single point [e.g. giving them a marker with plot(x,y,"o")], rather than as a single data set with four points. The matplotlib semantics would tend to suggest the former interpretation.

If PyPlot automatically transposes row vectors in plot, that would seem to make it difficult to do scatter plots with multiple single-point data sets.

dcarrera commented 9 years ago

I am not sure I understand. Wouldn't both interpretations result in the same plot? Either way you would get four points on the plot. No?

stevengj commented 9 years ago

No, because if they are from different datasets then (a) the points will have different colors by default and (b) they won't be connected by lines if you specify a line style. (There are other implications as well; these are just the most visible.)