-
Notifications
You must be signed in to change notification settings - Fork 981
Closed
Labels
Description
Issue: When I zoom in on either the top or right axis of the graph, the drawing appears to be incorrect. However, when I zoom inside the graph, it works fine.
ScottPlot Version: 5.0.28
Code Sample:
using System.Windows;
using ScottPlot;
using ScottPlot.TickGenerators;
namespace trips.playback.plotters.scottplot
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
}
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
// plot sample data
formsPlot1.Plot.Add.Signal(Generate.Sin(51, mult: 100_000));
formsPlot2.Plot.Add.Signal(Generate.Sin(51, mult: 100_000));
// add labels
formsPlot1.Plot.Axes.Left.Label.Text = "Vertical Axis";
formsPlot2.Plot.Axes.Left.Label.Text = "Vertical Axis";
formsPlot1.Plot.Axes.Bottom.Label.Text = "Horizontal Axis";
formsPlot2.Plot.Axes.Bottom.Label.Text = "Horizontal Axis";
// use a fixed size for the left axis panel to ensure it's always aligned
float leftAxisSize = 90;
formsPlot1.Plot.Axes.Left.MinimumSize = leftAxisSize;
formsPlot1.Plot.Axes.Left.MaximumSize = leftAxisSize;
formsPlot2.Plot.Axes.Left.MinimumSize = leftAxisSize;
formsPlot2.Plot.Axes.Left.MaximumSize = leftAxisSize;
// when one plot changes update the other plot
formsPlot1.Plot.RenderManager.AxisLimitsChanged += (s, e) =>
{
ApplyLayoutToOtherPlot(formsPlot1, formsPlot2);
};
formsPlot2.Plot.RenderManager.AxisLimitsChanged += (s, e) =>
{
ApplyLayoutToOtherPlot(formsPlot2, formsPlot1);
};
formsPlot1.Plot.Axes.AutoScale();
formsPlot2.Plot.Axes.AutoScale();
PrimaryGroup();
SecondaryGroup();
// initial render
formsPlot1.Refresh();
formsPlot2.Refresh();
}
private void PrimaryGroup()
{
var newax = formsPlot1.Plot.Axes.Top;
var customticks = new NumericManual();
customticks.AddMajor(1, "A");
customticks.AddMajor(10, "B");
customticks.AddMajor(50, "C");
customticks.AddMajor(100, "D");
customticks.AddMajor(200, "E");
newax.TickGenerator = customticks;
var serie = formsPlot1.Plot.Add.Signal(Generate.Cos(51, mult:100_000));
serie.Color = Colors.Red;
serie.Axes.XAxis = newax;
serie.Axes.YAxis = formsPlot1.Plot.Axes.Left;
}
private void SecondaryGroup()
{
var serie = formsPlot1.Plot.Add.Signal(Generate.Consecutive(51, 1));
serie.Color = Colors.Purple;
serie.Axes.YAxis = formsPlot1.Plot.Axes.Right;
}
private void ApplyLayoutToOtherPlot(IPlotControl source, IPlotControl dest)
{
AxisLimits axesBefore = dest.Plot.Axes.GetLimits();
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);
AxisLimits axesAfter = dest.Plot.Axes.GetLimits();
if (axesBefore != axesAfter)
{
dest.Refresh();
}
}
}
}
Reactions are currently unavailable