Skip to content

[BUG] Cycling arguments #2980

@briochemc

Description

@briochemc

Plots.jl cycling arguments (but only sometimes) makes for a confusing experience. With Plots.jl v1.6.4, depending the backend,

scatter(1:10, 1:3)

either:

  • plots by repeating 1:3 with, e.g., GR and PyPlot:
    gr pyplot

  • plots only the first 3 points with, e.g., UnicodePlots:
    unicodeplots

  • or errors with, e.g., Plotly:

    julia> plotly()
    Plots.PlotlyBackend()
    
    julia> scatter(1:10, 1:3)
    Error showing value of type Plots.Plot{Plots.PlotlyBackend}:
    ERROR: BoundsError: attempt to access 3-element UnitRange{Int64} at index [1:10]

I think it should either always error, or at least throw a warning.

Related issue: Note I read that

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.

Originally posted by @mkborregaard in #1151 (comment)

But I think think this cycling of arguments is not a good idea. (My opinion being biased by having been sent into a 3-day rabbit-hole expedition because of that "feature".)

While I understand the appeal of being able to do things like scatter(1:4, [1]), I think it exposes the risk that someone (like me) mistakenly plots scatter(x,y) with x and y of different lengths, and cannot figure out what is happening. This is true especially for large-ish datasets that produce a somehow dense cloud of data. I would personally prefer the behavior to be only valid when calling a scalar, i.e. for scatter(1:4, 1) to actually do what scatter(1:4, [1]) currently does, but I think that may conflict with other things (e.g., what is discussed in #2129).

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pyplot x
plotly x
plotlyjs x
pgfplotsx x
inspectdr x
unicodeplots x

Versions

  • Plots.jl version: v1.6.4
  • Backend version (]st -m):
    • GR v0.52.0
    • PyPlot v2.9.0
    • UnicodePlots v1.3.0
  • Output of versioninfo():
    julia> versioninfo()
    Julia Version 1.5.1
    Commit 697e782ab8 (2020-08-25 20:08 UTC)
    Platform Info:
      OS: macOS (x86_64-apple-darwin19.5.0)
      CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
      WORD_SIZE: 64
      LIBM: libopenlibm
      LLVM: libLLVM-9.0.1 (ORCJIT, skylake)

Edit: Fixed the MWE (1:10 instead of 1:20)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions