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

AxisAuto() should ignore invisible plots #623

Closed
kutukvpavel opened this issue Nov 22, 2020 · 2 comments
Closed

AxisAuto() should ignore invisible plots #623

kutukvpavel opened this issue Nov 22, 2020 · 2 comments

Comments

@kutukvpavel
Copy link

Hi!
First of all, great library, exactly what I was looking for to plot my real-time data! I'm using the latest release version.

I have several scatter plots in one WPF control and I'm able to control their visibility (I've linked Plot.visible fields to some checkboxes). However, I noticed that plot visibility doesn't affect AxisAuto() result. Is it possible to exclude hidden plots from computation of the limits?

@swharden
Copy link
Member

Hi @kutukvpavel, I'm happy to hear you are enjoying this library!

You're right that AxisAuto() adjusts the scale to fit all data (even if it's not visible). It does seem like a good idea to update this behavior so it only fits visible data. This could be done by modifying this portion of the code so it ignores plottables where visible is not true. I may do this in the next release of ScottPlot 4.0

https://github.com/swharden/ScottPlot/blob/4bf514cfe65e19d644db25f961a81f30e44caa2d/src/ScottPlot/Settings.cs#L201-L208

However, you can achieve this right away by implementing your own automatic axis function. Here's a console application which demonstrates how to do this. I hope you find it useful!

var plt = new ScottPlot.Plot();

// make a small plot
var small = plt.PlotScatter(new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 });

// make a large invisible plot
var big = plt.PlotScatter(new double[] { 10, 20, 30 }, new double[] { 10, 20, 30 });
big.visible = false;

// set axis limits traditionally (fits invisible plots)
plt.AxisAuto();

// determine axis limits of all visible plots
var visiblePlottables = plt.GetPlottables().Where(x => x.visible);
var limits = visiblePlottables.First().GetLimits();
foreach (var plottable in visiblePlottables)
    limits.ExpandXY(small.GetLimits());

// set axis limits based on visible plot limits and zoom out a bit
plt.Axis(limits.x1, limits.x2, limits.y1, limits.y2);
plt.AxisZoom(.9, .9);

plt.SaveFig("test.png");

image

@swharden swharden changed the title Taking plot visibility into account when autoscaling AxisAuto() should ignore invisible plots Nov 22, 2020
@swharden swharden removed the Question label Nov 22, 2020
@swharden
Copy link
Member

I may do this in the next release of ScottPlot 4.0

To keep things consistent I didn't change the behavior in ScottPlot 4.0 but I did do this for 4.1 (not yet released).

The code example above should fully achieve what you're trying to do in the mean time though! 👍

Thanks again for the tip
Scott

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

No branches or pull requests

2 participants