QuLogic on v3.5.0-doc
Merge pull request #21631 from … Merge pull request #21769 from … (compare)
QuLogic on v3.5.x
Merge pull request #21631 from … Merge pull request #21770 from … (compare)
I'm hitting what appears to be a bug with x mouse coords on a realtime animation
import datetime as dt import matplotlib.pyplot as plt import matplotlib.animation as animation fig, axes = plt.subplots(nrows=2, ncols=1) ax_price, ax_vols = axes xs, ys = ,  import math from time import time t0 = time() # This function is called periodically from FuncAnimation def animate(i, xs, ys): y = math.sin(i/10) xs.append(time() - t0) ys.append(y) ax_price.clear() ax_price.plot(xs, ys) def on_click(event): # print(time(), event) ax = event.inaxes x, y, button = event.xdata, event.ydata, event.button print(x) plt.connect('button_press_event', on_click) # Set up plot to call animate() function periodically ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys), interval=50) plt.show()
Now if I click to the right of the axis containing the animating-sine-wave, I would expect the x value to give me roughly the time elapsed since the start of execution.
However some values are failing to output correctly:
2.2027204626029535 0.8588709677419354 0.8588709677419354 4.586874788326601 5.252901354335969 5.775638770384171 6.237269535949154 0.8588709677419354 7.125060982377299 7.654645980077404 0.8588709677419354 8.655085787177086 0.8588709677419354 0.8588709677419354 10.025456918631832
It looks as though sometimes I'm getting the x in the range [0,1] (it reports ~0.85, and I clicked close to the right of the subplot)
Other times it works.
I'm guessing the redraw is interfering with the calculation of the x-value.
.. plot::directive in examples / tutorials if we want to include instuctive plots, where the code is not important, e.g. references. The downside is that it doesn't generate 2x images and you cannot use it for the thumbnail. - Seems I still have to wait that somebody implements foldable code boxes for sphinx-gallery.
fig, ax = plt.subplot_mosaic('AABB', figsize=(5, 2), constrained_layout=True) pm = ax["A"].pcolormesh(np.random.randn(100, 100)) plt.colorbar(pm, ax=ax['A'], shrink=0.69, pad=0) fig.align_ylabels()