Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior among backends for x and y of different length #1151

Closed
juliohm opened this issue Oct 9, 2017 · 10 comments
Closed

Inconsistent behavior among backends for x and y of different length #1151

juliohm opened this issue Oct 9, 2017 · 10 comments
Labels

Comments

@juliohm
Copy link

juliohm commented Oct 9, 2017

I spent almost an hour trying to debug an algorithm thinking that it had a bug when actually the plot function was doing some magic behind the scenes:

x = collect(1:200)
y = collect(1:100)

plot(x,y)

cycle

As you can see, the plot is cycled whenever the input vectors have different length. Is there a good rationale for doing this instead of throwing an error or warning the user?

@lnacquaroli
Copy link

I can reproduce it with pyplot() backend.
However, with gr() I am getting the following:

using Plots
gr()
x = collect(1:200)
y = collect(1:100)
plot(x,y)
Error showing value of type Plots.Plot{Plots.GRBackend}: ERROR: BoundsError: attempt to access 100-element Array{Int64,1} at index [1:200] Stacktrace: [1] throw_boundserror(::Array{Int64,1}, ::Tuple{UnitRange{Int64}}) at ./abstractarray.jl:433 [2] checkbounds at ./abstractarray.jl:362 [inlined] [3] getindex(::Array{Int64,1}, ::UnitRange{Int64}) at ./array.jl:526 [4] gr_display(::Plots.Subplot{Plots.GRBackend}, ::Measures.Length{:mm,Float64}, ::Measures.Length{:mm,Float64}, ::Array{Float64,1}) at /home/leniac/.julia/v0.6/Plots/src/backends/gr.jl:973 [5] gr_display(::Plots.Plot{Plots.GRBackend}) at /home/leniac/.julia/v0.6/Plots/src/backends/gr.jl:551 [6] _display(::Plots.Plot{Plots.GRBackend}) at /home/leniac/.julia/v0.6/Plots/src/backends/gr.jl:1326 [7] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/plain")}, ::Plots.Plot{Plots.GRBackend}) at /home/leniac/.julia/v0.6/Plots/src/output.jl:149 [8] display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::Plots.Plot{Plots.GRBackend}) at ./REPL.jl:125 [9] display(::Plots.Plot{Plots.GRBackend}) at ./multimedia.jl:194 [10] eval(::Module, ::Any) at ./boot.jl:235 [11] print_response(::Base.Terminals.TTYTerminal, ::Any, ::Void, ::Bool, ::Bool, ::Void) at ./REPL.jl:144 [12] print_response(::Base.REPL.LineEditREPL, ::Any, ::Void, ::Bool, ::Bool) at ./REPL.jl:129 [13] (::Base.REPL.#do_respond#16{Bool,Base.REPL.##26#36{Base.REPL.LineEditREPL,Base.REPL.REPLHistoryProvider},Base.REPL.LineEditREPL,Base.LineEdit.Prompt})(::Base.LineEdit.MIState, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Bool) at ./REPL.jl:646

@juliohm
Copy link
Author

juliohm commented Oct 9, 2017

Thank you @lnacquaroli , it seems that this issue is PyPlot specific then.

@lnacquaroli
Copy link

So it seems, although when using PyPlot (outside Plots) I get an empty plot with the following error:

plot(x,y)
ERROR: PyError (ccall(@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, arg, C_NULL)) <type 'exceptions.ValueError'> ValueError(u'x and y must have same first dimension, but have shapes (200,) and (100,)',) File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 3318, in plot ret = ax.plot(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1894, in inner return func(ax, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 1406, in plot for line in self._get_lines(*args, **kwargs): File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 407, in _grab_next_args for seg in self._plot_args(remaining, kwargs): File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 385, in _plot_args x, y = self._xy_from_xy(x, y) File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 244, in _xy_from_xy "have shapes {} and {}".format(x.shape, y.shape)) ...

@juliohm
Copy link
Author

juliohm commented Oct 9, 2017

Yes, this is definitely some Plots.jl magic, not something from Matplotlib.

@mkborregaard
Copy link
Member

Plots is intended to cycle input arguments, this allows you to do things like scatter(1:4, [1]). But it's a good question why the backends are inconsistent! Plotlyjs has a third behaviour - it plots (1:100, 1:100). I hope you're OK with my renaming of the issue.

@mkborregaard mkborregaard changed the title Rationale for plot behavior with vectors of different size Inconsisten behavior among backends for x and y of different length Oct 9, 2017
@mkborregaard mkborregaard changed the title Inconsisten behavior among backends for x and y of different length Inconsistent behavior among backends for x and y of different length Oct 9, 2017
@lnacquaroli
Copy link

lnacquaroli commented Oct 9, 2017

I think plotlyjs behavior might be the most tolerable world if one wants to prevent error messages without falling into misunderstanding like pyplot cycling. Cycling the data explicitly is preferred overall, IMO.

@juliohm
Copy link
Author

juliohm commented Mar 4, 2020

There are so many inconsistencies across backends, I think we can focus the work and efforts in the Makie ecosystem with new recipes and so on. Closing this for now.

@juliohm juliohm closed this as completed Mar 4, 2020
@mkborregaard
Copy link
Member

@juliohm you've closed a number of issues without posting reasons. Is that because the issues no longer exist, or do you just want to (like above) signal that they are low priority for you?

@juliohm
Copy link
Author

juliohm commented Mar 4, 2020 via email

@mkborregaard
Copy link
Member

ok cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants