Struct sb_rust_library::plotter::Plot [−][src]
Struct used to plot data and generate images.
A plot represents a single drawing area. The region of the image that data
is plotted to is refered to as the canvas
, which by default, is inset
within the full image. The size of the canvas can be changed with
with_drawing_bounds
.
A plot has two notions of coordinates: "logical" coordinates which are real-
valued coordinates that are plotted and "physical" coordinates which are the
integer locations of actual pixels. The range of logical coordinates
displayed can be changed with with_plotting_range
.
Currently data can only be plotted with the low level primitives
Circle
and Line
. This makes
plotting somewhat cumbersome, but it also makes this system flexible.
Examples
Basic sine wave without axis labels
let mut p = Plot::new(300, 200) .with_canvas_color(GREY) .with_bg_color(BLUE) .with_plotting_range(0.0..(2.0 * 3.14), -1.1..1.1) .with_drawing_bounds(0.05..0.95, 0.1..0.95); let x_values: Vec<f64> = (0..1000).map(|i| (i as f64) / 1000.0 * 2.0 * 3.14).collect(); let points: Vec<Point> = x_values.into_iter().map(|x| { (x, x.sin()).into() }).collect(); let circle = Circle::new(RED, 1); p.draw_circles(&circle, &points); p.save("sine-wave.bmp").unwrap();
Fields
width: i64
The width of the output image.
height: i64
The width of the output image.
frame: PlotFrame
Internal only: TODO: Make private
Implementations
impl Plot
[src]
pub fn new(width: u32, height: u32) -> Plot
[src]
Creates a new plot with the given image dimensions.
pub fn clear(&mut self)
[src]
Clears all plotted primitives, redrawing the plot frame and canvas.
pub fn draw_line<P>(&mut self, point1: P, point2: P, color: Color) where
P: Into<(f64, f64)>,
[src]
P: Into<(f64, f64)>,
Draws a line segment with the given logical coordinate endpoints.
pub fn draw_pixel_line(&mut self, p1: (f64, f64), p2: (f64, f64), color: Color)
[src]
Draws a line segment with the given physical pixel endpoints.
pub fn draw_orientations(
&mut self,
orientation: &Orientation,
positions: &[Point],
angles: &[f64]
)
[src]
&mut self,
orientation: &Orientation,
positions: &[Point],
angles: &[f64]
)
Plots data as line segments with the given logical positions and angles.
pub fn draw_circles(&mut self, circle: &Circle, positions: &[Point])
[src]
Plots data as circles with the given logical positions.
pub fn save(&self, filename: &str) -> Result<(), ImageError>
[src]
Saves contents of plot as an image.
pub fn put_pixel_safe(&mut self, x: i64, y: i64, c: Color)
[src]
Sets a pixel value, respecting bounds of plotting frame.
pub fn with_drawing_bounds<R: Into<Range<f64>>>(
self,
x_bounds: R,
y_bounds: R
) -> Self
[src]
self,
x_bounds: R,
y_bounds: R
) -> Self
Changes the fraction of the plot image that the plotting canvas takes up.
This accepts ranges of fractions between 0.0 and 1.0 indicating the portion of the plot that the plottable area takes up. All plotted data is displayed in this area. A bordering frame is drawn around the plotting canvas.
pub fn with_plotting_range<R: Into<Range<f64>>>(
self,
x_range: R,
y_range: R
) -> Self
[src]
self,
x_range: R,
y_range: R
) -> Self
Changes the logical coordinate range displayed in the plot.
For example, (0.0, 2.0 * PI), (-1.0, 1.0)
would correspond to displaying
a single period of a standard sine function.
pub fn with_bg_color(self, color: Color) -> Self
[src]
Changes the background color of the plot image (behind the canvas).
pub fn with_canvas_color(self, color: Color) -> Self
[src]
Changes the background color of the plotting canvas.
pub fn with_frame_color(self, color: Option<Color>) -> Self
[src]
Changes the color of the border around the plotting canvas.
Auto Trait Implementations
impl RefUnwindSafe for Plot
[src]
impl Send for Plot
[src]
impl Sync for Plot
[src]
impl Unpin for Plot
[src]
impl UnwindSafe for Plot
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,