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
Is your feature request related to a problem? Please describe.
I want to be able to plot data on a logarithmic scale. Either just x, just y or both axes.
Describe the solution you'd like
It would be easiest to have an implementation that would only need one call in the constructor:
let my_plot = Plot::new("My Plot").height(height).width(width).log_axes([false,self.log_mode]).legend(Legend::default());
which adds the correct formatters and adds a logarithmic_grid_spacer:
/// Fill in all values between [min, max]fngenerate_marks_log_plot(step_sizes:[f64;3],bounds:(f64,f64)) -> Vec<GridMark>{letmut steps = vec![];make_marks_log_plot(&mut steps, step_sizes, bounds);
steps
}/// Fill in all values between [min, max] which are a multiple of `step_size`fnmake_marks_log_plot(out:&mutVec<GridMark>,step_size:[f64;3],(min, max):(f64,f64)){assert!(max > min);// TODO: pos/neg checklet first = (min).floor()asi64;let last = (max).floor()asi64;letmut marks_iter = vec![];for i in first..=last {let step = (10_f64.powi(i asi32 + 1) - 10_f64.powi(i asi32)) / 9.0;
marks_iter.push(GridMark{value: i asf64,step_size: step_size[1],});for j in1..9{let value = 10_f64.powi(i asi32) + j asf64* step;
marks_iter.push(GridMark{value: value.log(10.0),step_size: step_size[0],});}}
out.extend(marks_iter);}pubfnlogarithmic_grid_spacer(log_base:i64) -> GridSpacer{let log_base = log_base asf64;let step_sizes = move |input:GridInput| -> Vec<GridMark>{// The distance between two of the thinnest grid lines is "rounded" up// to the next-bigger power of baselet smallest_visible_unit = next_power(input.base_step_size, log_base);let step_sizes = [
smallest_visible_unit,
smallest_visible_unit * log_base,
smallest_visible_unit * log_base * log_base,];generate_marks_log_plot(step_sizes, input.bounds)};Box::new(step_sizes)}
Still unfinished:
So far I am stuck with these things:
the logarithmic_grid_spacer fails to show new grid lines when we zoom in.
negative values or zero values in the data are not treated/ignored.
the origin (0,0) is shown in the plot at position (1,0) (I don't know how to turn that off), see screenshot above
I have not found a way to transform the data when self.log_axes[0] or self.log_axes[1] are set to true in the library files. In the example, this has to be done manually before handing the data over to Line::new() or similar:
Is your feature request related to a problem? Please describe.
I want to be able to plot data on a logarithmic scale. Either just x, just y or both axes.
Describe the solution you'd like
It would be easiest to have an implementation that would only need one call in the constructor:
to enable the log axes.
Describe alternatives you've considered
None
Additional context
I already started here.
Specifically, I started by adding the function
which adds the correct formatters and adds a
logarithmic_grid_spacer
:Still unfinished:
So far I am stuck with these things:
logarithmic_grid_spacer
fails to show new grid lines when we zoom in.self.log_axes[0]
orself.log_axes[1]
are set to true in the library files. In the example, this has to be done manually before handing the data over toLine::new()
or similar:any help/inputs are appreciated!
The text was updated successfully, but these errors were encountered: