Plots.jl: spy: Arrays have incorrect length or dimension.

Created on 23 Aug 2016  ·  9Comments  ·  Source: JuliaPlots/Plots.jl

Not sure if this is a Plots or GR issue.

julia> using Plots
julia> A = sprand(100, 35, 0.2);
julia> Plots.spy(A)
[Plots.jl] Initializing backend: gr
INFO: Recompiling stale cache file /Users/dpo/.julia/lib/v0.4/GR.ji for module GR.
Arrays have incorrect length or dimension.

With UnicodePlots:

julia> using Plots
julia> unicodeplots()
Plots.UnicodePlotsBackend()
julia> A = sprand(100, 35, 0.2);
julia> Plots.spy(A)
[Plots.jl] Initializing backend: unicodeplots
INFO: Recompiling stale cache file /Users/dpo/.julia/lib/v0.4/UnicodePlots.ji for module UnicodePlots.
ERROR: The backend must not support the series type Val{:heatmap}, and there isn't a series recipe defined.
 in error at /usr/local/Cellar/julia/0.4.5_1/lib/julia/sys.dylib
 [inlined code] from /Users/dpo/.julia/v0.4/Plots/src/series.jl:151
 in apply_recipe at /Users/dpo/.julia/v0.4/RecipesBase/src/RecipesBase.jl:238
 in _process_seriesrecipe at /Users/dpo/.julia/v0.4/Plots/src/pipeline.jl:386
 in _plot! at /Users/dpo/.julia/v0.4/Plots/src/plot.jl:204
 in heatmap at /Users/dpo/.julia/v0.4/Plots/src/Plots.jl:151
 in spy at /Users/dpo/.julia/v0.4/Plots/src/recipes.jl:942

However:

julia> using UnicodePlots
julia> A = sprand(100, 35, 0.2);
julia> UnicodePlots.spy(A)
        Sparsity Pattern
       ┌─────────────────┐
     1 │⠢⠠⠤⠀⠂⠀⢐⠆⡑⠈⡀⠃⠁⠀⠀⠀⣐│ > 0
       │⠐⠂⠩⢘⠡⠀⢠⠈⢨⠃⠤⢉⢐⠈⡀⠓⠀│ < 0
       │⢄⢀⠀⠔⠆⠄⣀⠀⢠⡀⠊⠁⠈⠁⠆⠃⠈│
       │⢂⢊⠉⡀⠴⢀⠈⠡⢠⡀⠄⠠⠃⠈⠌⠠⠁│
       │⣰⣐⠇⢠⡀⡀⣄⠨⠠⠀⠄⡂⠀⠡⡄⠂⠄│
       │⠀⠉⢀⠐⠀⢁⡐⠰⠀⠀⡂⣀⠠⠄⠈⠔⠺│
       │⠀⠨⠀⡁⠠⠀⠀⠀⣾⡀⠊⠀⢈⠰⠆⢊⡀│
       │⠈⢂⠂⠀⠬⠐⡁⡀⠈⠂⢂⡜⠡⠠⠈⢣⡂│
       │⡦⢠⠀⡅⠃⠀⠃⠄⠁⠐⠊⡠⠨⠂⢤⠨⠁│
       │⡄⠡⡀⢠⡀⠥⢠⠃⠳⢐⠦⠀⠌⠔⣀⠀⠦│
       │⡅⠠⠤⠂⢀⡃⠌⠌⢠⠴⠐⡁⠢⠁⡄⢀⠀│
       │⡘⢃⠂⠄⠰⠀⡢⡄⠀⠌⠁⢀⠙⢈⠃⠀⠀│
       │⠐⠀⢀⠀⢰⠐⠥⠂⣀⢘⠀⢀⠀⢒⠱⠙⡐│
       │⣒⠈⠃⠌⡠⡀⠘⠐⠑⠈⡊⠴⠀⠂⠇⠒⠘│
       │⠔⠈⡊⠂⠀⠭⢰⠠⡐⠢⠀⠕⠦⠪⠒⠔⢁│
       │⠀⠈⠀⡈⢁⢀⢰⡁⠈⢗⠀⠆⠀⢂⠉⣁⡂│
       │⣐⠀⠡⠀⢄⠈⡒⡀⠸⢌⠁⠂⠀⠀⠈⠇⡠│
       │⠇⠠⠙⠀⠠⠁⠖⡁⠂⠀⠹⠂⠀⡂⠂⠐⠂│
       │⠀⠅⠁⡠⠊⠡⡀⠐⠠⠑⡄⠥⢒⢋⢀⠃⢢│
       │⠐⢌⣅⠀⠠⠀⢂⠢⢚⢂⠐⢙⢬⣈⠊⠁⢁│
       │⠥⠁⡀⡀⠀⠢⠂⠑⢡⢐⡌⠐⢈⠄⠄⠀⠐│
       │⠠⠄⠁⠅⢂⢒⠱⠌⠆⠀⠀⠐⠠⡀⠬⢀⠨│
       │⢄⠮⠀⠋⢀⡐⢢⠀⠀⣁⠀⠨⠁⠈⢠⣄⠢│
   100 │⢅⠈⠁⢚⠀⣰⠁⠀⢄⠀⢠⣄⢢⠐⠂⢈⠀│
       └─────────────────┘
       1                35
            nz = 676

Most helpful comment

Thanks. I submitted the original spy for UnicodePlots so I actually prefer it to a heatmap ;-).

All 9 comments

UnicodePlots has its own special spyplot, while plots uses heatmap to unify things between backends.

While I do like the current UnicodePlots.spy I will provide a heatmap with the next refactor of unicode plots, I want to do that soon but have not specific ETA on that

Thanks. I submitted the original spy for UnicodePlots so I actually prefer it to a heatmap ;-).

Got this working:

tmp

I removed spy from Plots, and added it to StatPlots as:

  • a user recipe, which wraps the matrix as a Surface and makes it a :spy seriestype
  • a series recipe, which can be handled natively by each backend.

So for unicodeplots I do special handling to call the spy method, but for other backends I don't support :spy natively and it gets converted into a heatmap.

You'll need Plots dev and StatPlots master.

I'm not quite sure I understand that decision; spy has to do with plotting the Wilkinson diagram, or sparsity pattern, of a sparse matrix, i.e., the location of its nonzeros. It's not a statistical plot per se. I think most users would know spy from Matlab and/or Matplotlib and expect a sort of scatter plot, not really a heatmap. The heatmap can be useful too, but should perhaps be called something else than spy. StatsPlots has a number of requirements that I personally never use. It's hard to justify all those requirements for a simple 1/0 plot that isn't really related to statistics.

I can be convinced to move it back to Plots if you feel strongly. However, I'm not 100% sure on exactly what it should do. A heatmap is probably best, but with NaNs for 0's?? If there are zeros in a sparse matrix (i.e. the value exists, and it's zero) is that "on" or "off" in the spy plot?

I'm just thinking that most people would expect spy to plot a sparsity pattern. A Google search for "sparsity pattern" shows almost exclusively 1/0 plots.

Here's the documentation of Matlab's spy as an example: https://www.mathworks.com/help/matlab/ref/spy.html. There's a marker where the matrix has a nonzero element. That's how I initially submitted it to UnicodePlots.

Here's an example with Matplotlib: http://stackoverflow.com/questions/18651869/scipy-equivalent-for-matlab-spy

Matlab uses imagesc to display a heatmap of a matrix. Here's an example: http://stackoverflow.com/questions/15676363/matlab-how-does-one-plot-a-heatmap-from-nxn-matrix. I'm not sure what the Plots equivalent would be.

I'd be happy with an optional argument to spy to obtain a heatmap (which looks great too, but on which it's sometimes harder to see a clear structure). I'm just hoping this can be moved back to Plots.

Working on changing this to a scatter result now. In Plots.

Many thanks!

julia> using Plots; gr();

julia> A = sprandn(100,350,0.2);

julia> spy(A)

tmp

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cortner picture cortner  ·  4Comments

PallHaraldsson picture PallHaraldsson  ·  4Comments

Cody-G picture Cody-G  ·  3Comments

ereday picture ereday  ·  3Comments

kersulis picture kersulis  ·  5Comments