'Max Value displayed on matplotlib plot following navigation

I'm trying to return the maximum data value shown on a plot flowing navigation (e.g. pan or zoom).

Currently ax.get_ylim(), returns the max value of the y axis, and not the data displayed. Is this a bug within Matplotlib?



Solution 1:[1]

This is the intended function of ax.get_ylim(). Without this function (and get_xlim) doing what it does, there would be no way to get the max and min values displayed on the chart.

You can use the following to achieve what you want:

max(df[df["columninquestion"] < ax.get_ylim()[1]]["columninquestion"])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BGeez