You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to plot 2 Y axes with a common X axis. So far I am able to plot the 2 graphs. I found the answer to plotting 2 Y axes from here : #4186
My code is as follows
let sin: PlotPoints = (0..1000).map(|i| {
let x = i as f64 * 0.01;
[x, x.sin()]
}).collect();
let line_1 = Line::new(sin);
let cos: PlotPoints = (0..1000).map(|i| {
let x = i as f64 * 0.01;
[x, x.cos()]
}).collect();
let line_2 = Line::new(cos);
let f_formatter = |mark: GridMark, _range: &RangeInclusive<f64>| {
let value = 0.5 * mark.value;
if value < 1e-06 {
String::new()
} else {
format!("{:.2}", value)
}
};
let z_formatter = |mark: GridMark, _range: &RangeInclusive<f64>| {
let value = 0.5 * mark.value;
if value < 1e-06 {
String::new()
} else {
format!("{:.2}", value)
}
};
// Create the plot with custom axes
let f_y_axis = AxisHints::new_y()
.label("sin")
.formatter(f_formatter)
.placement(egui_plot::HPlacement::Left);
let z_y_axis = AxisHints::new_y()
.label("cos")
.formatter(z_formatter)
.placement(egui_plot::HPlacement::Right);
// Define x-axis hints
let x_axes = vec![AxisHints::new_x().label("time")];
// Construct custom y-axis hints vector
let y_axes = vec![f_y_axis, z_y_axis];
let plot = Plot::new("custom_axes")
.allow_zoom(false)
.allow_boxed_zoom(false)
.allow_drag(false)
.legend(Legend::default())
.custom_x_axes(x_axes)
.custom_y_axes(y_axes);
plot.show(ui, |plot_ui| {
plot_ui.line(line_1.name("sin")); // HOW DO I SET THE MAX and MIN RANGE ?
plot_ui.line(line_2.name("cos")); // HOW DO I SET THE MAX and MIN RANGE ?
});
The cos and sin are just example lines. The main question is as follows :
Line 1 : It has bounds between 0 & 100. How do I set the ranges on Y(left) axis ?
Line 2 : It has bounds between 0 & 1000. How do I set the ranges on Y(right) axis ?
X : It has bounds between 0 & 10 . How do I set the ranges on X axis ?
The text was updated successfully, but these errors were encountered:
Shrav108
changed the title
How to set the range for X & Y Axes to be within a range in egui plot ?
Help !!! How to set proper bounds on Custom X & Y axis ?
Aug 5, 2024
Hi, I'm trying to plot 2 Y axes with a common X axis. So far I am able to plot the 2 graphs. I found the answer to plotting 2 Y axes from here : #4186
My code is as follows
The cos and sin are just example lines. The main question is as follows :
The text was updated successfully, but these errors were encountered: