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

Help !!! How to set proper bounds on Custom X & Y axis ? #4909

Closed
Shrav108 opened this issue Aug 3, 2024 · 1 comment
Closed

Help !!! How to set proper bounds on Custom X & Y axis ? #4909

Shrav108 opened this issue Aug 3, 2024 · 1 comment

Comments

@Shrav108
Copy link

Shrav108 commented Aug 3, 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

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 :

  1. Line 1 : It has bounds between 0 & 100. How do I set the ranges on Y(left) axis ?
  2. Line 2 : It has bounds between 0 & 1000. How do I set the ranges on Y(right) axis ?
  3. X : It has bounds between 0 & 10 . How do I set the ranges on X axis ?
@Shrav108 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
@bircni
Copy link
Contributor

bircni commented Aug 5, 2024

This is an issue for egui_plot please move it there https://github.com/emilk/egui_plot
See #4828

@Shrav108 Shrav108 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2024
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