Comments (12)
I now appreciate the issue is about multi-axis syncing across multiple plots. I think the issue is here, as it's not getting and setting all 4 axis limits. I'll create an updated code sample in a few minutes...
dest.Plot.Axes.SetLimits(source.Plot.Axes.GetLimits());
dest.Plot.Axes.SetLimitsX(source.Plot.Axes.GetLimits());
dest.Plot.Axes.SetLimitsX(source.Plot.Axes.GetLimits(), dest.Plot.Axes.Top);
from scottplot.
from scottplot.
@swharden This issue is the most critical because the user can reproduce easily and we don't have any workaround.
from scottplot.
Hi @rubenslkirchner, I made a simple app to test this out and it works as expected. Could the issue be related to something your code is doing differently? Hopefully this is enough to help you get your app working, but if not let me know and we can re-open this issue and take a closer look 👍
using ScottPlot;
namespace Sandbox.WinForms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var sig1 = formsPlot1.Plot.Add.Signal(Generate.Sin(mult: 0.001));
sig1.Axes.YAxis = formsPlot1.Plot.Axes.Left;
sig1.Axes.XAxis = formsPlot1.Plot.Axes.Bottom;
formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Left, sig1.Color);
formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Bottom, sig1.Color);
var sig2 = formsPlot1.Plot.Add.Signal(Generate.Cos(mult: 1000));
sig2.Axes.YAxis = formsPlot1.Plot.Axes.Right;
sig2.Axes.XAxis = formsPlot1.Plot.Axes.Top;
formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Right, sig2.Color);
formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Top, sig2.Color);
formsPlot1.Plot.HideGrid();
}
}
from scottplot.
This works for me, let me know if the strategy works for you too!
I changed the logic a bit: (1) I use a timer to manage axis copying and rendering for a little better performance and to ensure one plot isn't modified inside the render loop of another and (2) all axis limits are copied, not just the primary ones
using ScottPlot;
namespace Sandbox.WinForms;
public partial class Form1 : Form
{
readonly System.Windows.Forms.Timer RefreshTimer = new();
public Form1()
{
InitializeComponent();
// plot 1 signal 1
var sig1 = formsPlot1.Plot.Add.Signal(Generate.Sin(mult: 0.001));
sig1.Axes.YAxis = formsPlot1.Plot.Axes.Left;
sig1.Axes.XAxis = formsPlot1.Plot.Axes.Bottom;
formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Left, sig1.Color);
formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Bottom, sig1.Color);
// plot 1 signal 2
var sig2 = formsPlot1.Plot.Add.Signal(Generate.Cos(mult: 1000));
sig2.Axes.YAxis = formsPlot1.Plot.Axes.Right;
sig2.Axes.XAxis = formsPlot1.Plot.Axes.Top;
formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Right, sig2.Color);
formsPlot1.Plot.Axes.Color(formsPlot1.Plot.Axes.Top, sig2.Color);
formsPlot1.Plot.HideGrid();
// plot 2 signal 1
var sig3 = formsPlot2.Plot.Add.Signal(Generate.Sin(mult: 0.001));
sig3.Axes.YAxis = formsPlot2.Plot.Axes.Left;
sig3.Axes.XAxis = formsPlot2.Plot.Axes.Bottom;
formsPlot2.Plot.Axes.Color(formsPlot2.Plot.Axes.Left, sig1.Color);
formsPlot2.Plot.Axes.Color(formsPlot2.Plot.Axes.Bottom, sig1.Color);
// plot 2 signal 2
var sig4 = formsPlot2.Plot.Add.Signal(Generate.Cos(mult: 1000));
sig4.Axes.YAxis = formsPlot2.Plot.Axes.Right;
sig4.Axes.XAxis = formsPlot2.Plot.Axes.Top;
formsPlot2.Plot.Axes.Color(formsPlot2.Plot.Axes.Right, sig2.Color);
formsPlot2.Plot.Axes.Color(formsPlot2.Plot.Axes.Top, sig2.Color);
formsPlot2.Plot.HideGrid();
// when one plot changes update the other plot
formsPlot1.Plot.RenderManager.AxisLimitsChanged += (s, e) => PlotsToCopy = (formsPlot1, formsPlot2);
formsPlot2.Plot.RenderManager.AxisLimitsChanged += (s, e) => PlotsToCopy = (formsPlot2, formsPlot1);
// setup a timer to manage refreshes
RefreshTimer.Interval = 10;
RefreshTimer.Tick += (s, e) => CopyLimits();
RefreshTimer.Start();
}
private (IPlotControl from, IPlotControl to)? PlotsToCopy = null;
private void CopyLimits()
{
if (PlotsToCopy is null)
return;
(IPlotControl source, IPlotControl target) = PlotsToCopy.Value;
AxisLimits limits1 = source.Plot.Axes.GetLimits(source.Plot.Axes.Bottom, source.Plot.Axes.Left);
AxisLimits limits2 = source.Plot.Axes.GetLimits(source.Plot.Axes.Top, source.Plot.Axes.Right);
target.Plot.Axes.SetLimits(limits1, target.Plot.Axes.Bottom, target.Plot.Axes.Left);
target.Plot.Axes.SetLimits(limits2, target.Plot.Axes.Top, target.Plot.Axes.Right);
target.Refresh();
}
}
from scottplot.
The user is expecting that when zoomed on the left and right axis ALL series will increase or decrease and not just the series that are linked to the axis. Same thing for the top and bottom axes.
from scottplot.
Even version 5.0.29 has the same issue. The user was expecting that when scrolling on the Y axis, ALL series would change vertically. In the print I'm sending, notice that only the series in blue is changing the zoom.
from scottplot.
Ah, I understand the disconnect. Let me re-state your description of the issue:
"The user was expecting that when scrolling on the LEFT Y axis, the RIGHT Y axis would also change"
This is not the default behavior. The axis system was designed so whatever axis the cursor is over is the one that will be adjusted. However, I'm sure we can come up with a way to modify your code to achieve the functionality you're looking for. I'll re-open this issue as a reminder to revisit it later today and update you with the solution I come up with.
... quick idea in case you want to try this before I get to it, the last code sample I shared could be modified to evaluate "what percent the axis limits changed after copying", then you could call SetAxisLimits to change the other axis by that same percentage the first axis was changed.
bool leftAxisChanged = /* calculate this */
bool rightAxisChanged = /* calculate this */
if (leftAxisChanged){
double fractionLeftAxisChanged = /* calculate this */
formsPlot1.Plot.Axes.Right.Range.ZoomFrac(fractionLeftAxisChanged);
}
if (rightAxisChanged){
double fractionRightAxisChanged = /* calculate this */
formsPlot1.Plot.Axes.Left.Range.ZoomFrac(fractionRightAxisChanged);
}
from scottplot.
Trying to implement this myself and it's getting pretty dicey with all the logic checks. I'll see about adding a flag that enables behavior like "if the left axis changes, change the right axis by the same fractional amount".
Interestingly this feature is unrelated to multi-axis plots. This is the sample code I'm starting with
using ScottPlot;
namespace Sandbox.WinForms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var sig1 = formsPlot1.Plot.Add.Signal(Generate.Sin());
sig1.Axes.YAxis = formsPlot1.Plot.Axes.Left;
formsPlot1.Plot.Axes.Color(sig1.Axes.YAxis, sig1.Color);
var sig2 = formsPlot1.Plot.Add.Signal(Generate.Cos());
sig2.Axes.YAxis = formsPlot1.Plot.Axes.Right;
formsPlot1.Plot.Axes.Color(sig2.Axes.YAxis, sig2.Color);
}
}
from scottplot.
Logic blocks like this here are the offending code:
ScottPlot/src/ScottPlot5/ScottPlot5/Control/StandardActions.cs
Lines 108 to 114 in 01fd7c8
Modifying it a bit we start to observe the OP's desired behavior
from scottplot.
This feature will be in the next release as an opt-in feature:
formsPlot1.Interaction.ChangeOpposingAxesTogether = true;
from scottplot.
Scott, this new configuration was perfect! Thank you very much for your efforts!!!
from scottplot.
Related Issues (20)
- Box: Default stroke width is zero HOT 1
- My financial plot does not work with version ScottPlot (5.0.30) HOT 6
- Annotation: Text Position with Wrong Spacing HOT 4
- SVG with line breaks don't render correctly and tick marks inconsistent HOT 2
- Update 5.0.31: ScottPlot.Plottables.Crosshair does not show anymore (also not in "Demo" project) HOT 2
- Rendering: changing the plottable list mid-render will cause an exception HOT 2
- StandardZoomRectangle: make `LineStyle` setter public HOT 3
- Marker.MarkerLineWidth stopped working after v5.0.27 HOT 5
- ScottPlot 5: Stiatistical distribution issue HOT 1
- DateTimeFixedInterval not Generating Expected Daily Ticks HOT 2
- Legend: add option to disable column-based wrapping HOT 2
- Replace data of plottable HOT 2
- Add .Measure() functionality back in HOT 1
- AvaPlot does not show the bottom Axis Label under any circumstances HOT 2
- VectorField: Add ScaleFactor HOT 1
- SignalXY: add option for step display HOT 6
- Signal: List<T> low density rendering issue HOT 5
- SignalXY: How to get the nearest point to the mouse location HOT 4
- Axis: add option to wrap text HOT 1
- Plotting Mutiple Digital signals (1s & 0s) one below the other in a signle graph? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scottplot.