Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential matplotlib warning when using ui.line_plot.push #4192

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

drkspace
Copy link

@drkspace drkspace commented Jan 8, 2025

Description

When trying to use ui.line_plot.push with x or y values that are all equal, you get the following matplotlib warning:

lib/python3.12/site-packages/nicegui/elements/line_plot.py:72: UserWarning: Attempting to set identical low and high ylims makes transformation singular; automatically expanding.
  self.fig.gca().set_ylim(min_y - pad_y, max_y + pad_y)

This PR changes 2 things:

  1. It will not update the x and/or y limits if their respective data points are all the same value.
  2. Add update_y_lims and update_x_lims parameters to push that will disable the limits updating for that push. This will also allow for custom limits to be set (and not reset every call to push).

Example

This example will have a warning on the current version of nicegui.

from nicegui import ui

lp = ui.line_plot(n=1)

i = 0
def update_lp():
    global i
    lp.push([i], [[0]])
    # lp.push([i], [[0]], update_y_lims=False)

    i += 1
ui.timer(1, update_lp)
ui.run()

Not updating the limits if the xs and ys have not difference in value.

Added new parameters to disable updating a specific axis' limits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant