Scrollable plots

In this stack overflow post there is a Python solution to produce scrollable plots, which I could not find in Julia plotting packages.

Tried running the SO code below but got stuck at the def update(val): part:

using PyPlot, PyCall
@pyimport numpy as np
@pyimport matplotlib.widgets as wg

fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.25)

t = np.arange(0.0, 100.0, 0.1)
s = np.sin(2*np.pi*t)
l, = plt.plot(t,s)
plt.axis([0, 10, -1, 1])

axcolor = "lightgoldenrodyellow"
axpos = plt.axes([0.2, 0.1, 0.65, 0.03], facecolor=axcolor)

spos = wg.Slider(axpos, "Pos", 0.1, 90.0)

# how to translate this part:
def update(val):
    pos = spos.val
    ax.axis([pos,pos+10,-1,1])
    fig.canvas.draw_idle()

spos.on_changed(update)

plt.show()

Any help is appreciated.

Do you require something more than this Axis ?

Do you have a preference for using a slider/widget of some kind?

Thanks for your response.

Could you please confirm if Makie can do the following:

Let T(x) be the ground temperature at point x along a path between New York and Paris. Can we plot, say, 100 km of T(x) and have a scrollbar/slider to move quickly between the two endpoints 5800 km apart.

Note that this seems to be different from panning, which is slower / more painful.

I could be misunderstanding, but do you mean something like this?

using WGLMakie

fig = Figure()
ax = Axis(fig[1, 1])

# Set up slider
x = 0:0.1:10
sl_x = SliderGrid(fig[2, 1], (label="distance", range=x))

# Plot function
T(x) = sin(x) * exp(-x/4)
lines!(ax, x, T.(x))

# Update limits to pan window
x_obs = sl_x.sliders[1].value
@lift xlims!(ax, $x_obs - 1, $x_obs + 1)

fig
5 Likes

@icweaver, that is brilliant. Cheers.

1 Like

Plotly lets you zoom to an area of your chart and then drag the area to the left or right. That is called panning. There may be other backends that let you do that.