pub struct Contour { /* private fields */ }
Expand description
Generates a contour plot
See Matplotlib’s documentation
§Example
use plotpy::{Contour, Plot, 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§
source§impl Contour
impl Contour
sourcepub fn draw<'a, T, U>(&mut self, x: &'a T, y: &'a T, z: &'a T)
pub fn draw<'a, T, U>(&mut self, x: &'a T, y: &'a T, z: &'a T)
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
U
of 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
sourcepub fn set_extra_filled(&mut self, extra: &str) -> &mut Self
pub fn set_extra_filled(&mut self, extra: &str) -> &mut Self
Sets extra matplotlib commands (comma separated) for the filled contour
Important: The extra commands must be comma separated. For example:
param1=123,param2='hello'
sourcepub fn set_extra_line(&mut self, extra: &str) -> &mut Self
pub fn set_extra_line(&mut self, extra: &str) -> &mut Self
Sets extra matplotlib commands (comma separated) for the line contour
Important: The extra commands must be comma separated. For example:
param1=123,param2='hello'