Plots.jl: Update axis ticks and grid on zoom and pan using PyPlot backend

Created on 20 Jul 2016  Â·  9Comments  Â·  Source: JuliaPlots/Plots.jl

The axis ticks and grid lines are not updated when zooming and panning. Three images are provided to illustrate the issue.

  1. Default plot.
  2. Plot with zoom and pan, showing missing ticks and grid lines.
  3. Plot with zoom and pan, showing updated ticks, using PyPlot directly.

  1. Default plot Plots.plot(sin, 0, 2Ï€):
    default
  2. Zooming and panning:
    zoompan
  3. Same plot in PyPlot with zooming and panning, xs=0:0.1:2pi; PyPlot.plot(xs, sin(xs)):
    pyplotzoompan
PyPlot

Most helpful comment

Use ticks = :native

All 9 comments

The correct solution to this will be to short-circuit the matplotlib callbacks. I don't have a complete solution, but you can do this like:

using Plots; pyplot()
p = plot(rand(10))

onclick(event) = info("CLICK: $event")
fig = p.o
fig[:canvas][:mpl_connect]("button_press_event", onclick)

The idea would be to update the plot limits inside p and re-display the Plots.Plot object. The only trickiness is that we don't want to get in an infinite loop of re-drawing. Ideally we can just turn off the matplotlib gui events and update the plot ourselves.

I see this behaviour with several backends (PyPlot, GR, and PlotlyJS). It is a bit of an inconvenience during data exploration.

perhaps if there was a ticks=:backend option or something that just bypasses Plots tick handling and lets the backend handle tick placement?

Yeah that could be a good solution

On Wednesday, October 5, 2016, Spencer Russell [email protected]
wrote:

perhaps if there was a ticks=:backend option or something that just
bypasses Plots tick handling and lets the backend handle tick placement?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/tbreloff/Plots.jl/issues/394#issuecomment-251811392,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA492pdnBQ_8WsJOTprf-GjRisdCBFUWks5qxB0VgaJpZM4JQ0Jd
.

Being bitten by this right now. So sad it received no attention for over 2 years...

Use ticks = :native

Is it possible to extract the current zoom state? I'm not very experienced with recipes, but I'm trying to plot some mass spectrometry data. Conceptually, the data are stored as a sparse matrix with ~1000 columns but ~10^6 rows. The idea is that for a particular zoom state, I want to aggregate the rows within the zoom region into ~1000 "superrows". It would be something like

ylims = get_ylims()
xlims = get_xlims()
buffer = AxisArray(Matrix{T}(undef, 1000, 1000), Axis{:yname}(ylims), Axis{:xname}(xlims))
copyto!(buffer, masspecdata)   # this sums into "superrows", using just the part of masspecdata that is within the limits
imshow(buffer)

Is it possible to extract the current zoom state?

Not through Plots directly, however, you can access matplotlib objects from a plot and use matplotlib functions:

julia> using Plots; pyplot()
Plots.PyPlotBackend()

julia> p = plot(1:5) # make a plot

julia> sp = p[1] # select the 1st subplot
Subplot{1}

julia> pyaxis = sp.o # get the matplotlib axis object
PyObject <matplotlib.axes._axes.Axes object at 0x7f5100fc1690>

julia> ylims = pyaxis.get_ylim() # use matplotlib's get_ylim
(0.88, 5.12)

or in one line:

julia> p[1].o.get_ylim()
(0.88, 5.12)

After zooming interactively:

julia> p[1].o.get_ylim()
(2.5431878445728913, 4.622146084043291)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

tbenst picture tbenst  Â·  3Comments

crstnbr picture crstnbr  Â·  3Comments

kersulis picture kersulis  Â·  5Comments

lstagner picture lstagner  Â·  5Comments

asinghvi17 picture asinghvi17  Â·  3Comments