Each time I add new data to series, Y axis is panning/zooming automatically in order to fit new data into screen. How can I prevent Oxyplot from touching the axis? I would like to have the scale fixed all the time, no matter what data I feed to plot
As #Taw stated, the properties in oxyplot are the same:
plotModel.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Left,
Minimum = 0,
Maximum = 10,
});
plotModel.Axes.Add(new LinearAxis()
{
Position = AxisPosition.Bottom,
Minimum = 0,
Maximum = 10,
});
Related
I do a project to show multi signal waves vertically arrangement。when the signal type is different(bool vs unsigned short)(means max value different)。the two signals y axis cant be aligned in x direction(because the max y value string occupy different space),something like this
I hope 2 solutions
the max y value text can be placed in the right of y axis
the max y value can be set to occupy same space(max value 1 occupy 5 characters padleft with empty,max value 65535 occupy 5 characters)
this is my code:
var series1 = new LineSeries { Title = serietitle, MarkerType = MarkerType.Circle };
var dateTimeAxis1 = new DateTimeAxis() { Minimum = DateTimeAxis.ToDouble(DateTime.Now), Maximum = DateTimeAxis.ToDouble(DateTime.Now.AddHours(1)) };
//dateTimeAxis1.Title = "Time";
model.Axes.Add(dateTimeAxis1);
model.Series.Add(series1);
LinearAxis leftAxis = new LinearAxis()
{
Position = AxisPosition.Left,
AbsoluteMaximum= maxy,
IsAxisVisible = true, //
Minimum = 0,
Maximum = maxy,
Title = "SigValue",//
IsZoomEnabled = false,//
};
model.Axes.Add(leftAxis);
I'm trying to make my plot change it's interval type depending on the level of zoom but I'm not sure how to achieve this. I'm using a DateTimeAxis and would like it to start at Days. Then zooming out would change from days to months, finally to years. Zooming in would change from Days to hours, maybe seconds if this type of behavior is even possible.
Currently I have my axes setup as follows:
public DateTimeAxis HorizontalAxis
{
get
{
return new DateTimeAxis
{
Position = AxisPosition.Bottom,
Minimum = DateTimeAxis.ToDouble(Start),
Maximum = DateTimeAxis.ToDouble(End),
MajorStep = double.NaN,
MinimumMajorStep = 0,
MinorStep = double.NaN,
MinimumMinorStep = 0,
AbsoluteMinimum = DateTimeAxis.ToDouble(Start),
AbsoluteMaximum = DateTimeAxis.ToDouble(End),
MinorIntervalType = DateTimeIntervalType.Hours,
IntervalType = DateTimeIntervalType.Days,
Title = " Date Time Axis Title "
};
}
}
public LinearAxis VerticalAxis
{
get
{
return new LinearAxis
{
Position = AxisPosition.Left,
Minimum = SetPoint - 4,
Maximum = SetPoint + 4,
MajorStep = double.NaN,
MinimumMajorStep = 0,
MinorStep = 0.5,
MinimumMinorStep = 0,
AbsoluteMinimum = SetPoint - 4,
AbsoluteMaximum = SetPoint + 4,
MinorTickSize = 0,
Title = " Linear Axis Title "
};
}
}
If this type of behavior is not possible I would also ask if there is a way to get hours to show when zooming in from days. When making a default plot this was the behavior I saw.
Thanks!
I know I just posted this question but perhaps there are other people who are interested in getting this type of behavior.
To dynamically change the axis I used the AxisChanged event described Here
From there I created an output message to see what properties were changing in the axes. I found that the Scale, Minor Step Size, and Major Step Size are what changes on zooming. Implementing a simple if statement to check the scale I was able to get the behavior I desired.
private async void Horizontal_AxisChanged(object sender, AxisChangedEventArgs e)
{
DateTimeAxis horizontal = sender as DateTimeAxis;
if(horizontal.Scale > 100)
{
horizontal.IntervalType = DateTimeIntervalType.Hours;
}
else if(horizontal.Scale < 100)
{
horizontal.IntervalType = DateTimeIntervalType.Days;
}
}
I create a new Plot and its PlotModel with a black BackgroundColor
Then I create a new Axes. The X-Axis doesn't matter, it's invisible.
The Y-Axis is:
var valueAxisY = new OxyPlot.Axes.LinearAxis(AxisPosition.Left, minValue, maxValue)
{
AxislineThickness = 2,
AxislineColor = OxyColors.White,
MinorGridLinethickness = 2,
MajorGridLineThickness = 2,
MinorTickSize = 4,
MajorTickSize = 7,
TicklineColor = OxyColors.White,
FontSize = 40,
TextColor = OxyColors.White
}
Everything works BUT the Y-Axisline. It seems to stay black no matter what. The ticks starting 1-2 pixels on the left of where the line should be are white and have the correct length.
Is this the wrong parameter?
The trick was Undefined.
var valueAxisY = new OxyPlot.Axes.LinearAxis(AxisPosition.Left, minValue, maxValue)
{
LineStyle = LineStyle.Undefined
};
Somehow this is a visible, editable, continuous line.
If you define the axis line you should also hide the border arround plot area, because it is drawn over the axis line.
using model.PlotAreaBorderThickness = 0
I'm trying to draw a threshold (1 line from left to right). To do so I add the threshold value twice and the value 0 and 1 for xValues then set the scale of X to be from 0 to 1.
public static void AddThreshold(Chart xlChart, double value, string name, int color, bool secondary)
{
Series series = xlChart.SeriesCollection().NewSeries();
series.Name = name;
series.XValues = new List<int>() { 0, 1 }.ToArray();
series.Values = new List<double>() { value, value }.ToArray();
Axis xAxis, yAxis;
if (secondary)
{
series.AxisGroup = XlAxisGroup.xlSecondary;
xAxis = (Axis)xlChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlSecondary);
yAxis = (Axis)xlChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlSecondary);
}
else
{
xAxis = (Axis)xlChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);
yAxis = (Axis)xlChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary);
}
xAxis.MinimumScale = 0;//getting COM error here
xAxis.MaximumScale = 1;
yAxis.Delete();
series.ChartType = XlChartType.xlXYScatterLinesNoMarkers;
series.MarkerSize = 3;
series.Border.LineStyle = XlMarkerStyle.xlMarkerStyleDash;
series.Border.Color = color;
}
But I'm always getting a COM error and can't figure out the problem. To make things more annoying the exact method was working in a different project (don't ask about it because the code there was partially deleted by mistake and I am not rewriting it).
You can't set min and max of an axis if it's not a value type of axis, and only XY Scatter charts have an X axis that is a value axis. You need to specify the chart type of the added series as XY Scatter before setting the axis scale.
So move this:
series.ChartType = XlChartType.xlXYScatterLinesNoMarkers;
above this:
xAxis.MinimumScale = 0;
I'm currently playing around with the ILNumerics API and started to plot a few points in a cube.
Then I calculated a regression plane right through those points.
Now I'd like to plot the plane in the same scene plot but only with the same size than the point cloud.
I got the paramters of the plane (a,b,c): f(x,y) = a*x + b*y + c;
I know that only z is interesting for plotting a plane but I've got no clue how pass the right coodinates to the scene so that the plane size is about the same size than the maximum and minimum area of the points.
Could you guys give me a simple example of plotting a plane and a little suggetion how to set the bounds of that plane right?
Here is what I got so far:
private void ilPanel1_Load(object sender, EventArgs e)
{
// get the X and Y bounds and calculate Z with parameters
// plot it!
var scene = new ILScene {
new ILPlotCube(twoDMode: false) {
new ILSurface( ??? ) {
}
}
};
// view angle etc
scene.First<ILPlotCube>().Rotation = Matrix4.Rotation(
new Vector3(1f, 0.23f, 1), 0.7f);
ilPanel1.Scene = scene;
}
I hope that someone can help me ...
Thanks in advance !!!
You could take the Limits of the plotcube.Plots group and derive the coords from the bounding box from it. This gives you the min and max x and y coord for the plane. Use them to get the corresponding z values by evaluating you plane equation.
Once you have x,y and z of the plane, use them with ILSurface to plot the plane.
If you need more help, I can try to add an example.
#Edit: the following Example plots a plane through 3 arbitrary points. The planes orientation and position is computed by help of a plane function zEval. Its coefficients a,b,c are computed here from the 3 (concrete) points. You will have to compute your own equation coefficients here.
The plane is realized with a surface. One might as well take the 4 coords computed in 'P' and use an ILTriangleFan and an ILLineStrip to create the plane and the border. But the surface already comes with a Fill and a Wireframe, so we take this as a quick solution.
private void ilPanel1_Load(object sender, EventArgs e) {
// 3 arbitrary points
float[,] A = new float[3, 3] {
{ 1.0f, 2.0f, 3.0f },
{ 2.0f, 2.0f, 4.0f },
{ 2.0f, -2.0f, 2.0f }
};
// construct a new plotcube and plot the points
var scene = new ILScene {
new ILPlotCube(twoDMode: false) {
new ILPoints {
Positions = A,
Size = 4,
}
}
};
// Plane equation: this is derived from the concrete example points. In your
// real world app you will have to adopt the weights a,b and c to your points.
Func<float, float, float> zEval = (x, y) => {
float a = 1, b = 0.5f, c = 1;
return a * x + b * y + c;
};
// find bounding box of the plot contents
scene.Configure();
var limits = scene.First<ILPlotCube>().Plots.Limits;
// Construct the surface / plane to draw
// The 'plane' will be a surface constructed from a 2x2 mesh only.
// The x/y coordinates of the corners / grid points of the surface are taken from
// the limits of the plots /points. The corresponding Z coordinates are computed
// by the zEval function. So we give the ILSurface constructor not only Z coordinates
// as 2x2 matrix - but an Z,X,Y Array of size 2x2x3
ILArray<float> P = ILMath.zeros<float>(2, 2, 3);
Vector3 min = limits.Min, max = limits.Max;
P[":;:;1"] = new float[,] { { min.X, min.X }, { max.X, max.X } };
P[":;:;2"] = new float[,] { { max.Y, min.Y }, { max.Y, min.Y } };
P[":;:;0"] = new float[,] {
{ zEval(min.X, max.Y) , zEval(min.X, min.Y) },
{ zEval(max.X, max.Y) , zEval(max.X, min.Y) },
};
// create the surface, make it semitransparent and modify the colormap
scene.First<ILPlotCube>().Add(new ILSurface(P) {
Alpha = 0.6f,
Colormap = Colormaps.Prism
});
// give the scene to the panel
ilPanel1.Scene = scene;
}
This would create an image similar to this one:
#Edit2: you asked, how to disable the automatic scaling of the plot cube while adding the surface:
// before adding the surface:
var plotCube = scene.First<ILPlotCube>();
plotCube.AutoScaleOnAdd = false;
Alternatively, you can set the limits of the cube manually:
plotCube.Limits.Set(min,max);
You probably will want to disable some mouse interaction as well, since they would allow the user to rescale the cube in a similar (unwanted?) way:
plotCube.AllowZoom = false; // disables the mouse wheel zoom
plotCube.MouseDoubleClick += (_,arg) => {
arg.Cancel = true; // disable the double click - resetting for the plot cube
};