pub struct Contour { /* private fields */ }Expand description
Generates a contour plot
Example
use plotpy::{Contour, Plot};
use russell_lab::generate3d;
fn main() -> Result<(), &'static str> {
// generate (x,y,z) matrices
let n = 21;
let (x, y, z) = generate3d(-2.0, 2.0, -2.0, 2.0, n, n, |x, y| x * x - y * y);
// configure contour
let mut contour = Contour::new();
contour
.set_colorbar_label("temperature")
.set_colormap_name("terrain")
.set_selected_line_color("#f1eb67")
.set_selected_line_width(12.0)
.set_selected_level(0.0, true);
// draw contour
contour.draw(&x, &y, &z);
// add contour to plot
let mut plot = Plot::new();
plot.add(&contour)
.set_labels("x", "y");
// save figure
plot.save("/tmp/plotpy/doc_tests/doc_contour.svg")?;
Ok(())
}See also integration tests in the tests directory
Output from some integration tests:
Implementations
sourceimpl Contour
impl Contour
sourcepub fn draw<'a, T, U>(&mut self, x: &'a T, y: &'a T, z: &'a T) where
T: AsMatrix<'a, U>,
U: 'a + Display,
pub fn draw<'a, T, U>(&mut self, x: &'a T, y: &'a T, z: &'a T) where
T: AsMatrix<'a, U>,
U: 'a + Display,
Draws a fancy contour: filled contour with a line contour and a colorbar
Input
x– matrix with x valuesy– matrix with y valuesz– matrix with z values
Flags
The following flags control what features are not to be drawn:
no_lines– skip drawing a lines contour on top of the filled contourno_labels– skip adding labels to the lines contour (if enabled)no_colorbar– skip drawing a colorbarwith_selected– draw a line contour with a selected level (e.g., 0.0) on top of everything
Notes
- The type
Uof the input matrices must be a number.
sourcepub fn set_colors(&mut self, colors: &[&str]) -> &mut Self
pub fn set_colors(&mut self, colors: &[&str]) -> &mut Self
Sets the colors to be used instead of a pre-defined colormap
Will use colormap_index instead if its empty.
sourcepub fn set_levels(&mut self, levels: &[f64]) -> &mut Self
pub fn set_levels(&mut self, levels: &[f64]) -> &mut Self
Sets pre-defined levels, otherwise automatically calculate levels
sourcepub fn set_colormap_index(&mut self, index: usize) -> &mut Self
pub fn set_colormap_index(&mut self, index: usize) -> &mut Self
Sets the colormap index
Options:
- 0 – bwr
- 1 – RdBu
- 2 – hsv
- 3 – jet
- 4 – terrain
- 5 – pink
- 6 – Greys
>6 – starts over from 0
sourcepub fn set_colormap_name(&mut self, name: &str) -> &mut Self
pub fn set_colormap_name(&mut self, name: &str) -> &mut Self
Sets the colormap name
Colormap names:
Will use colormap_index instead if colormap_name is empty.
sourcepub fn set_no_lines(&mut self, flag: bool) -> &mut Self
pub fn set_no_lines(&mut self, flag: bool) -> &mut Self
Sets option to skip drawing a lines contour on top of the filled contour
sourcepub fn set_no_labels(&mut self, flag: bool) -> &mut Self
pub fn set_no_labels(&mut self, flag: bool) -> &mut Self
Sets option to skip adding labels to the lines contour (if enabled)
sourcepub fn set_no_inline_labels(&mut self, flag: bool) -> &mut Self
pub fn set_no_inline_labels(&mut self, flag: bool) -> &mut Self
Sets option to skip drawing labels inline with the contour lines (if enabled)
sourcepub fn set_no_colorbar(&mut self, flag: bool) -> &mut Self
pub fn set_no_colorbar(&mut self, flag: bool) -> &mut Self
Sets option to skip drawing a colorbar
sourcepub fn set_colorbar_label(&mut self, label: &str) -> &mut Self
pub fn set_colorbar_label(&mut self, label: &str) -> &mut Self
Sets the colorbar label
sourcepub fn set_number_format_cb(&mut self, format: &str) -> &mut Self
pub fn set_number_format_cb(&mut self, format: &str) -> &mut Self
Sets the number format for the labels in the colorbar (cb)
sourcepub fn set_line_color(&mut self, color: &str) -> &mut Self
pub fn set_line_color(&mut self, color: &str) -> &mut Self
Sets the line color for the lines contour (default is black)
sourcepub fn set_line_style(&mut self, style: &str) -> &mut Self
pub fn set_line_style(&mut self, style: &str) -> &mut Self
Sets the line style for the lines contour
Options:
- “
-”, “:”, “--”, “-.”
sourcepub fn set_line_width(&mut self, width: f64) -> &mut Self
pub fn set_line_width(&mut self, width: f64) -> &mut Self
Sets the line width for the lines contour
sourcepub fn set_fontsize_labels(&mut self, fontsize: f64) -> &mut Self
pub fn set_fontsize_labels(&mut self, fontsize: f64) -> &mut Self
Sets the font size for labels
sourcepub fn set_selected_level(&mut self, level: f64, enabled: bool) -> &mut Self
pub fn set_selected_level(&mut self, level: f64, enabled: bool) -> &mut Self
Sets option to draw a line contour with a selected level (e.g., 0.0)
Will draw the selected level (e.g., 0.0) on top of everything
sourcepub fn set_selected_line_color(&mut self, color: &str) -> &mut Self
pub fn set_selected_line_color(&mut self, color: &str) -> &mut Self
Sets the color to mark the selected level
sourcepub fn set_selected_line_style(&mut self, style: &str) -> &mut Self
pub fn set_selected_line_style(&mut self, style: &str) -> &mut Self
Sets the line style for the selected level
Options:
- “
-”, “:”, “--”, “-.”
sourcepub fn set_selected_line_width(&mut self, width: f64) -> &mut Self
pub fn set_selected_line_width(&mut self, width: f64) -> &mut Self
Sets the line width for the selected level
Trait Implementations
sourceimpl GraphMaker for Contour
impl GraphMaker for Contour
sourcefn get_buffer<'a>(&'a self) -> &'a String
fn get_buffer<'a>(&'a self) -> &'a String
Returns the text buffer with Python3 commands
sourcefn clear_buffer(&mut self)
fn clear_buffer(&mut self)
Clear the text buffer with Python commands
Auto Trait Implementations
impl RefUnwindSafe for Contour
impl Send for Contour
impl Sync for Contour
impl Unpin for Contour
impl UnwindSafe for Contour
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more