ax.relim() completely ignores changes to scatterplots with .set_offsets().
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()
No response
Windows
3.9.1
tkAgg
3.11.9
None
pip
Limit handling has historically been quite a mess, unfortunately there is little consistency across artists. See #15595 (comment).
@CyfralCoot maybe it can help you, but I did an autoscale function to handle all kind of artist. You can have a look here: https://github.com/mp-007/kivy_matplotlib_widget/blob/main/kivy_matplotlib_widget/uix/graph_subplot_widget.py#L186
It is a built-in function inside my kivy widget, but it can give you some guidelines.
Hi, I’d like to work on this issue. I’ll start by reproducing the bug locally and then look into how relim() handles scatter artists.
The PR that "fixed" this was only marked as merged because its commits were contained in a second PR that was merged, but that second PR reverted all the changes from the first PR, so this isn't actually fixed.
Human gold patch for matplotlib__matplotlib-31128
BUG: Fix relim() to support Collection artists (scatter, etc.) relim(…
BUG: Preserve autolim=False semantics for Collection relim support
Activity
timhoffm commented on Dec 15, 2025
Limit handling has historically been quite a mess, unfortunately there is little consistency across artists. See #15595 (comment).
mp-007 commented on Jan 26, 2026
@CyfralCoot maybe it can help you, but I did an autoscale function to handle all kind of artist. You can have a look here: https://github.com/mp-007/kivy_matplotlib_widget/blob/main/kivy_matplotlib_widget/uix/graph_subplot_widget.py#L186
It is a built-in function inside my kivy widget, but it can give you some guidelines.
Archiljain commented on Feb 9, 2026
Hi, I’d like to work on this issue.
I’ll start by reproducing the bug locally and then look into how relim() handles scatter artists.
QuLogic commented on Mar 7, 2026
The PR that "fixed" this was only marked as merged because its commits were contained in a second PR that was merged, but that second PR reverted all the changes from the first PR, so this isn't actually fixed.
Human gold patch for matplotlib__matplotlib-31128
BUG: Fix relim() to support Collection artists (scatter, etc.) relim(…
BUG: Fix relim() to support Collection artists (scatter, etc.) relim(…
BUG: Fix relim() to support Collection artists (scatter, etc.) relim(…
BUG: Preserve autolim=False semantics for Collection relim support