Skip to content

How to set the scale of the x-axis in a Plot #4402

Answered by RMcTn
jjimenezroda asked this question in Q&A
Discussion options

You must be logged in to vote

You could set the plot bounds on first draw so the initial view is how you want it to be, but the user can then zoom/scroll as normal. Would this be closer to the behaviour you'd like?

            
            let mut first_draw = true; // Set somewhere outside of the egui loop
            
            let min_x_timestamp = ...;
            let max_x_timestamp = ...;
            egui_plot::Plot::new("plot")
                .show(ui, |plot_ui| {
                    if first_draw {
                        // Initial plot bound is only set once, rather than every time the plot gets redrawn
                        first_draw = false;
                        plot_ui.set_plot_bounds(PlotBounds:…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jjimenezroda
Comment options

@RMcTn
Comment options

Answer selected by jjimenezroda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants