1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
//! Rust plotting library using Python and Matplotlib
//!
//! This library implements high-level functions to generate plots and drawings.
//! Although we use Python/Matplotlib, the goal is to provide a convenient Rust library
//! that is **different** than Matplotlib. The difference happens because we want **convenience**
//! for the Rust developer while getting the **fantastic quality of Matplotlib** 😀.
//!
//! Internally, we use [Matplotlib](https://matplotlib.org/) via a Python 3 script.
//! First, we generate a python code in a directory of your choice (e.g., `/tmp/plotpy`),
//! and then we call **python3** using Rust's [std::process::Command].
//!
//! The Python script has the same name as the figure name given to the [Plot::save] function,
//! but with the `.py` extension. The figure name can have the (png, pdf, or svg) extension
//! (see [Matplotlib](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html))
//! for more information regarding file extensions.
//!
//! We generate the Python script with the preamble listed in [PYTHON_HEADER] and the file
//! should be useful for double checking or even directly adding Python/Matplotlib commands,
//! in case the functionality is not implemented here yet.
//!
//! When calling [Plot::save] or [Plot::save_and_show], if an error occurs, we generate a log
//! file in the same output directory with the same filename as the figure (and python script),
//! but with the `.log` extension.
//!
//! The typical use of this library is by allocating structures such as [Canvas], [Curve], [Contour],
//! [Histogram], [Surface], [Text] (and more) and then passing them to [Plot] for the generation
//! of the files mentioned above. The [Plot::save_and_show] function may also be used to immediately
//! see the plot or drawing on the screen.
//!
//! Each structure (e.g. [Curve], [Legend], or [Text]) defines many configuration options
//! that can be set by calling their own `set_...` function. Typically, these structures provide
//! `draw_...` functions to plot/draw features. Afterwards, we call [Plot::add] to add these structures
//! to the [Plot] and then call [Plot::save]. The `draw` method of each object must be called
//! before adding to `Plot`.
//!
//! # Example
//!
//! ```
//! use plotpy::{generate3d, Plot, StrError, Surface};
//!
//! fn main() -> Result<(), StrError> {
//! let mut surface = Surface::new();
//! surface
//! .set_with_wireframe(true)
//! .set_colormap_name("Pastel1")
//! .set_with_colorbar(true)
//! .set_colorbar_label("temperature")
//! .set_wire_line_color("#1862ab")
//! .set_wire_line_style(":")
//! .set_wire_line_width(0.75);
//!
//! // draw surface
//! let n = 9;
//! let (x, y, z) = generate3d(-2.0, 2.0, -2.0, 2.0, n, n, |x, y| x * x + y * y);
//! surface.draw(&x, &y, &z);
//!
//! // add surface to plot
//! let mut plot = Plot::new();
//! plot.add(&surface);
//!
//! // save figure
//! plot.save("/tmp/plotpy/example_main.svg")?;
//! Ok(())
//! }
//! ```
//!
//! ![example_main.svg](https://raw.githubusercontent.com/cpmech/plotpy/main/figures/example_main.svg)
/// Defines a type alias for the error type as a static string
pub type StrError = &'static str;
// modules ////////////////////////////////////////
mod as_matrix;
mod as_vector;
mod auxiliary;
mod canvas;
mod constants;
mod contour;
mod conversions;
mod curve;
mod fileio;
mod histogram;
mod legend;
mod plot;
mod slope_icon;
mod super_title_params;
mod surface;
mod surface_geometry;
mod text;
pub use crate::as_matrix::*;
pub use crate::as_vector::*;
pub use crate::auxiliary::*;
pub use crate::canvas::*;
pub use crate::constants::*;
pub use crate::contour::*;
use crate::conversions::*;
pub use crate::curve::*;
use crate::fileio::*;
pub use crate::histogram::*;
pub use crate::legend::*;
pub use crate::plot::*;
pub use crate::slope_icon::*;
pub use crate::super_title_params::*;
pub use crate::surface::*;
pub use crate::text::*;
// run code from README file
#[cfg(doctest)]
mod test_readme {
macro_rules! external_doc_test {
($x:expr) => {
#[doc = $x]
extern "C" {}
};
}
external_doc_test!(include_str!("../README.md"));
}