Bug summary
ax.relim() completely ignores changes to scatterplots with .set_offsets().
Code for reproduction
import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import numpy as np
class App:
def __init__(self, root):
self.root = root
fig = Figure(figsize=(5, 5), dpi=100)
self.ax = fig.add_subplot(111)
self.canvas = FigureCanvasTkAgg(fig, root)
self.canvas.get_tk_widget().pack(fill="both", expand=True)
self.toolbar = NavigationToolbar2Tk(self.canvas, root)
# Create artists once
self.scatter = self.ax.scatter([], [])
self.line, = self.ax.plot([], [])
root.after(1000, self.update_plot)
def update_plot(self):
# New data every update
xs = np.linspace(0, 10, 100)
ys = np.sin(xs) + np.random.normal(scale=0.1, size=100)
# Update artists
self.scatter.set_offsets(np.column_stack((xs, ys)))
#self.line.set_data(xs, ys) #Uncomment this to see the expected behaviour
# Autoscale (not working)
self.ax.relim()
self.ax.autoscale_view()
self.canvas.draw_idle()
# Keep updating
self.root.after(1000, self.update_plot)
root = tk.Tk()
App(root)
root.mainloop()
Actual outcome
Expected outcome
Additional information
No response
Operating system
Windows
Matplotlib Version
3.9.1
Matplotlib Backend
tkAgg
Python version
3.11.9
Jupyter version
None
Installation
pip
Bug summary
ax.relim() completely ignores changes to scatterplots with .set_offsets().
Code for reproduction
Actual outcome
Expected outcome
Additional information
No response
Operating system
Windows
Matplotlib Version
3.9.1
Matplotlib Backend
tkAgg
Python version
3.11.9
Jupyter version
None
Installation
pip