pub struct Text { /* private fields */ }Expand description
Creates text annotations for 2D or 3D plots with optional bounding boxes
Supports draw for 2D and draw_3d for 3D placement.
Optional bounding boxes can be styled via the set_bbox_* methods.
See Matplotlib’s documentation
§Example
use plotpy::{Plot, Text, StrError};
use std::path::Path;
fn main() -> Result<(), StrError> {
// configure text
let mut text = Text::new();
text.set_color("purple")
.set_align_horizontal("center")
.set_align_vertical("center")
.set_fontsize(30.0)
.set_bbox(true)
.set_bbox_facecolor("pink")
.set_bbox_edgecolor("black")
.set_bbox_alpha(0.3)
.set_bbox_style("roundtooth,pad=0.3,tooth_size=0.2");
// draw text
text.draw_3d(0.5, 0.5, 0.5, "Hello World!");
// add text to plot
let mut plot = Plot::new();
plot.add(&text);
// save figure
plot.set_save_pad_inches(0.25)
.save("/tmp/plotpy/doc_tests/doc_text.svg")?;
Ok(())
}Implementations§
Source§impl Text
impl Text
Sourcepub fn draw_3d<T>(&mut self, x: T, y: T, z: T, message: &str)
pub fn draw_3d<T>(&mut self, x: T, y: T, z: T, message: &str)
Draws text at (x, y, z) in a 3D plot
Requires Plot::set_subplot_3d to be called first.
§Input
x,y,z– coordinates (data coordinates)message– text string to display
See also: draw for 2D text
Sourcepub fn set_align_horizontal(&mut self, option: &str) -> &mut Self
pub fn set_align_horizontal(&mut self, option: &str) -> &mut Self
Sets the horizontal alignment
Options: “center”, “left”, “right”
Sourcepub fn set_align_vertical(&mut self, option: &str) -> &mut Self
pub fn set_align_vertical(&mut self, option: &str) -> &mut Self
Sets the vertical alignment
Options: “center”, “top”, “bottom”, “baseline”, “center_baseline”
Sourcepub fn set_fontsize(&mut self, fontsize: f64) -> &mut Self
pub fn set_fontsize(&mut self, fontsize: f64) -> &mut Self
Sets the font size
Sourcepub fn set_rotation(&mut self, rotation: f64) -> &mut Self
pub fn set_rotation(&mut self, rotation: f64) -> &mut Self
Sets the text rotation angle in degrees (2D only)
See https://matplotlib.org/stable/api/text_api.html#matplotlib.text.Text.set_rotation
Sourcepub fn set_bbox_facecolor(&mut self, color: &str) -> &mut Self
pub fn set_bbox_facecolor(&mut self, color: &str) -> &mut Self
Sets facecolor of bounding box
Sourcepub fn set_bbox_edgecolor(&mut self, color: &str) -> &mut Self
pub fn set_bbox_edgecolor(&mut self, color: &str) -> &mut Self
Sets edgecolor of bounding box
Sourcepub fn set_bbox_alpha(&mut self, value: f64) -> &mut Self
pub fn set_bbox_alpha(&mut self, value: f64) -> &mut Self
Sets alpha of bounding box
Sourcepub fn set_bbox_style(&mut self, style: &str) -> &mut Self
pub fn set_bbox_style(&mut self, style: &str) -> &mut Self
Sets style of bounding box; example
Examples:
- “square,pad=0.3”
- “circle,pad=0.3”
- “larrow,pad=0.3”
- “rarrow,pad=0.3”
- “darrow,pad=0.3”
- “round,pad=0.3,rounding_size=0.15”
- “round4,pad=0.3,rounding_size=0.2”
- “sawtooth,pad=0.3,tooth_size=0.1”
- “roundtooth,pad=0.3,tooth_size=0.2”
See Matplotlib