question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plot: Create GetDataLimits() for returning X/Y limits of all plotted data

See original GitHub issue

ScottPlot Version: 4.1.26

Operating System: W10

Application Type: WinForms

Question: I need to limit zoom out. I would like that it doesn’t go beyond the AxisAuto(). I know I can implement on application side something to compute Min/Max of existing data and use SetOuterViewLimits to achieve this. However, I am wondering, wouldn’t be easier and more suited to have this functionality build in into Scottplot? It could be a flag that we can set to limit zoom out to maximum the AxisAuto() fit.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
swhardencommented, Oct 30, 2021

Hi @EFeru, thanks for posting this issue! I agree the current strategy is a bit clunky, and I’d love to figure-out a way to improve it.

Calculating min/max of existing data is actually pretty costly performance wise, so I wouldn’t want to do it automatically before each render. Instead I think the way to go is to have the user perform this task (they know best when the data may change).

What do you think about code that did something like this?

AxisLimits limits = myPlot.GetDataLimits();
myPlot.SetOuterViewLimits(limits);

Basically it’s a way to get the limits from AxisAuto() without actually resizing the window yet. What do you think about this potential solution?

0reactions
swhardencommented, Jan 5, 2022

Oh, I see more recent conversation in #1532

Restating the problem, adding a plottable with an infinite axis (e.g., axis lines which extend to infinity) results in unexpected behavior:

ScottPlot.Plot plt = new(400, 300);
Random rand = new(0);
double[] xs = ScottPlot.DataGen.Random(rand, 10);
double[] ys = ScottPlot.DataGen.Random(rand, 10);
plt.AddScatter(xs, ys);
plt.AddVerticalLine(13); // <-- this extends to infinity in the Y direction
Console.WriteLine(plt.GetDataLimits());
AxisLimits: x=[0.2060331540210327, 13] y=[NaN, NaN]

I’ll add a comment in #1532 regarding how to best fix this

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get the limits of plotted data from a Figure or Axes ...
First, just as a side note, from the fact that you want the data at point in the code where you only have...
Read more >
Specify Axis Limits - MATLAB & Simulink
Specify the axis limits using the xlim and ylim functions. For 3-D plots, use the zlim function. Pass the functions a two-element vector...
Read more >
Data disappears from plot when setting axes limits?
I want to be able to set the axes limits on all three, however when I do the plots return with no data...
Read more >
Set Axis Limits of Plot in R
In this example, we will be setting up the limits of the y-axis from -20 to 20 of the given plot of 10...
Read more >
Matplotlib | Set the Axis Range | Scaler Topics
In this article, we will go over different ways to set the axis range of our plots. Setting the range of axes in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found