Struct plotpy::Text

source ·
pub struct Text { /* private fields */ }
Expand description

Creates text to be added to a plot

§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_rotation(45.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.save("/tmp/plotpy/doc_tests/doc_text.svg")?;
    Ok(())
}

doc_text.svg

Implementations§

source§

impl Text

source

pub fn new() -> Self

Creates a new Text object

source

pub fn draw(&mut self, x: f64, y: f64, message: &str)

Draws text

source

pub fn draw_3d(&mut self, x: f64, y: f64, z: f64, message: &str)

Draws text in 3D plot

source

pub fn set_color(&mut self, color: &str) -> &mut Self

Sets the text color

source

pub fn set_align_horizontal(&mut self, option: &str) -> &mut Self

Sets the horizontal alignment

Options: “center”, “left”, “right”

source

pub fn set_align_vertical(&mut self, option: &str) -> &mut Self

Sets the vertical alignment

Options: “center”, “top”, “bottom”, “baseline”, “center_baseline”

source

pub fn set_fontsize(&mut self, fontsize: f64) -> &mut Self

Sets the font size

source

pub fn set_rotation(&mut self, rotation: f64) -> &mut Self

Sets the text rotation

source

pub fn set_bbox(&mut self, flag: bool) -> &mut Self

Sets use bounding box flag

source

pub fn set_bbox_facecolor(&mut self, color: &str) -> &mut Self

Sets facecolor of bounding box

source

pub fn set_bbox_edgecolor(&mut self, color: &str) -> &mut Self

Sets edgecolor of bounding box

source

pub fn set_bbox_alpha(&mut self, value: f64) -> &mut Self

Sets alpha of bounding box

source

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

Trait Implementations§

source§

impl GraphMaker for Text

source§

fn get_buffer<'a>(&'a self) -> &'a String

Returns the text buffer with Python3 commands
source§

fn clear_buffer(&mut self)

Clear the text buffer with Python commands

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnwindSafe for Text

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.