56 lines
14 KiB
HTML
56 lines
14 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Rust plotting library using Python and Matplotlib"><title>plotpy - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="plotpy" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../plotpy/index.html">plotpy</a><span class="version">0.5.1</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li></ul><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#constants" title="Constants">Constants</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#functions" title="Functions">Functions</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>plotpy</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/plotpy/lib.rs.html#1-118">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Rust plotting library using Python and Matplotlib</p>
|
||
<p>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 <strong>different</strong> than Matplotlib. The difference happens because we want <strong>convenience</strong>
|
||
for the Rust developer while getting the <strong>fantastic quality of Matplotlib</strong> 😀.</p>
|
||
<p>Internally, we use <a href="https://matplotlib.org/">Matplotlib</a> via a Python 3 script.
|
||
First, we generate a python code in a directory of your choice (e.g., <code>/tmp/plotpy</code>),
|
||
and then we call <strong>python3</strong> using Rust’s <a href="https://doc.rust-lang.org/1.84.0/std/process/struct.Command.html" title="struct std::process::Command">std::process::Command</a>.</p>
|
||
<p>The Python script has the same name as the figure name given to the <a href="struct.Plot.html#method.save" title="method plotpy::Plot::save">Plot::save</a> function,
|
||
but with the <code>.py</code> extension. The figure name can have the (png, pdf, or svg) extension
|
||
(see <a href="https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html">Matplotlib</a>)
|
||
for more information regarding file extensions.</p>
|
||
<p>We generate the Python script with the preamble listed in <a href="constant.PYTHON_HEADER.html" title="constant plotpy::PYTHON_HEADER">PYTHON_HEADER</a> 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.</p>
|
||
<p>When calling <a href="struct.Plot.html#method.save" title="method plotpy::Plot::save">Plot::save</a> or <a href="struct.Plot.html#method.save_and_show" title="method plotpy::Plot::save_and_show">Plot::save_and_show</a>, 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 <code>.log</code> extension.</p>
|
||
<p>The typical use of this library is by allocating structures such as <a href="struct.Canvas.html" title="struct plotpy::Canvas">Canvas</a>, <a href="struct.Curve.html" title="struct plotpy::Curve">Curve</a>, <a href="struct.Contour.html" title="struct plotpy::Contour">Contour</a>,
|
||
<a href="struct.Histogram.html" title="struct plotpy::Histogram">Histogram</a>, <a href="struct.Surface.html" title="struct plotpy::Surface">Surface</a>, <a href="struct.Text.html" title="struct plotpy::Text">Text</a> (and more) and then passing them to <a href="struct.Plot.html" title="struct plotpy::Plot">Plot</a> for the generation
|
||
of the files mentioned above. The <a href="struct.Plot.html#method.save_and_show" title="method plotpy::Plot::save_and_show">Plot::save_and_show</a> function may also be used to immediately
|
||
see the plot or drawing on the screen.</p>
|
||
<p>Each structure (e.g. <a href="struct.Curve.html" title="struct plotpy::Curve">Curve</a>, <a href="struct.Legend.html" title="struct plotpy::Legend">Legend</a>, or <a href="struct.Text.html" title="struct plotpy::Text">Text</a>) defines many configuration options
|
||
that can be set by calling their own <code>set_...</code> function. Typically, these structures provide
|
||
<code>draw_...</code> functions to plot/draw features. Afterwards, we call <a href="struct.Plot.html#method.add" title="method plotpy::Plot::add">Plot::add</a> to add these structures
|
||
to the <a href="struct.Plot.html" title="struct plotpy::Plot">Plot</a> and then call <a href="struct.Plot.html#method.save" title="method plotpy::Plot::save">Plot::save</a>. The <code>draw</code> method of each object must be called
|
||
before adding to <code>Plot</code>.</p>
|
||
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>plotpy::{generate3d, Plot, StrError, Surface};
|
||
|
||
<span class="kw">fn </span>main() -> <span class="prelude-ty">Result</span><(), StrError> {
|
||
<span class="kw">let </span><span class="kw-2">mut </span>surface = Surface::new();
|
||
surface
|
||
.set_with_wireframe(<span class="bool-val">true</span>)
|
||
.set_colormap_name(<span class="string">"Pastel1"</span>)
|
||
.set_with_colorbar(<span class="bool-val">true</span>)
|
||
.set_colorbar_label(<span class="string">"temperature"</span>)
|
||
.set_line_color(<span class="string">"#1862ab"</span>)
|
||
.set_line_style(<span class="string">":"</span>)
|
||
.set_line_width(<span class="number">0.75</span>);
|
||
|
||
<span class="comment">// draw surface
|
||
</span><span class="kw">let </span>n = <span class="number">9</span>;
|
||
<span class="kw">let </span>(x, y, z) = generate3d(-<span class="number">2.0</span>, <span class="number">2.0</span>, -<span class="number">2.0</span>, <span class="number">2.0</span>, n, n, |x, y| x * x + y * y);
|
||
surface.draw(<span class="kw-2">&</span>x, <span class="kw-2">&</span>y, <span class="kw-2">&</span>z);
|
||
|
||
<span class="comment">// add surface to plot
|
||
</span><span class="kw">let </span><span class="kw-2">mut </span>plot = Plot::new();
|
||
plot.add(<span class="kw-2">&</span>surface);
|
||
|
||
<span class="comment">// save figure
|
||
</span>plot.save(<span class="string">"/tmp/plotpy/example_main.svg"</span>)<span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div>
|
||
<p><img src="https://raw.githubusercontent.com/cpmech/plotpy/main/figures/example_main.svg" alt="example_main.svg" /></p>
|
||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Canvas.html" title="struct plotpy::Canvas">Canvas</a></div><div class="desc docblock-short">Implements functions to draw 2D and 3D features, including poly-lines and Bezier curves</div></li><li><div class="item-name"><a class="struct" href="struct.Contour.html" title="struct plotpy::Contour">Contour</a></div><div class="desc docblock-short">Generates a contour plot</div></li><li><div class="item-name"><a class="struct" href="struct.Curve.html" title="struct plotpy::Curve">Curve</a></div><div class="desc docblock-short">Generates a curve (aka line-plot) given two arrays (x,y)</div></li><li><div class="item-name"><a class="struct" href="struct.Histogram.html" title="struct plotpy::Histogram">Histogram</a></div><div class="desc docblock-short">Generates a Histogram plot</div></li><li><div class="item-name"><a class="struct" href="struct.Legend.html" title="struct plotpy::Legend">Legend</a></div><div class="desc docblock-short">Generates a Legend</div></li><li><div class="item-name"><a class="struct" href="struct.Plot.html" title="struct plotpy::Plot">Plot</a></div><div class="desc docblock-short">Driver structure that calls Python</div></li><li><div class="item-name"><a class="struct" href="struct.SlopeIcon.html" title="struct plotpy::SlopeIcon">Slope<wbr>Icon</a></div><div class="desc docblock-short">Creates an icon to indicate the slope of lines</div></li><li><div class="item-name"><a class="struct" href="struct.SuperTitleParams.html" title="struct plotpy::SuperTitleParams">Super<wbr>Title<wbr>Params</a></div><div class="desc docblock-short">Holds parameters for the SuperTitle</div></li><li><div class="item-name"><a class="struct" href="struct.Surface.html" title="struct plotpy::Surface">Surface</a></div><div class="desc docblock-short">Generates a 3D a surface (or wireframe, or both)</div></li><li><div class="item-name"><a class="struct" href="struct.Text.html" title="struct plotpy::Text">Text</a></div><div class="desc docblock-short">Creates text to be added to a plot</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.PolyCode.html" title="enum plotpy::PolyCode">Poly<wbr>Code</a></div><div class="desc docblock-short">Defines the poly-curve code</div></li><li><div class="item-name"><a class="enum" href="enum.RayEndpoint.html" title="enum plotpy::RayEndpoint">RayEndpoint</a></div><div class="desc docblock-short">Holds either the second point coordinates of a ray or the slope of the ray</div></li></ul><h2 id="constants" class="section-header">Constants<a href="#constants" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="constant" href="constant.PYTHON_HEADER.html" title="constant plotpy::PYTHON_HEADER">PYTHON_<wbr>HEADER</a></div><div class="desc docblock-short">Commands to be added at the beginning of the Python script</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.AsMatrix.html" title="trait plotpy::AsMatrix">AsMatrix</a></div><div class="desc docblock-short">Defines a trait to handle Matrix-like data</div></li><li><div class="item-name"><a class="trait" href="trait.AsVector.html" title="trait plotpy::AsVector">AsVector</a></div><div class="desc docblock-short">Defines a trait to handle Vector-like data</div></li><li><div class="item-name"><a class="trait" href="trait.GraphMaker.html" title="trait plotpy::GraphMaker">Graph<wbr>Maker</a></div><div class="desc docblock-short">Defines the trait used by Plot to add graph entities</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.generate2d.html" title="fn plotpy::generate2d">generate2d</a></div><div class="desc docblock-short">Generates 2d points (meshgrid)</div></li><li><div class="item-name"><a class="fn" href="fn.generate3d.html" title="fn plotpy::generate3d">generate3d</a></div><div class="desc docblock-short">Generates 3d points (function over meshgrid)</div></li><li><div class="item-name"><a class="fn" href="fn.linspace.html" title="fn plotpy::linspace">linspace</a></div><div class="desc docblock-short">Returns evenly spaced numbers over a specified closed interval</div></li><li><div class="item-name"><a class="fn" href="fn.sign.html" title="fn plotpy::sign">sign</a></div><div class="desc docblock-short">Implements the sign function</div></li><li><div class="item-name"><a class="fn" href="fn.suq_cos.html" title="fn plotpy::suq_cos">suq_cos</a></div><div class="desc docblock-short">Implements the superquadric auxiliary involving cos(x)</div></li><li><div class="item-name"><a class="fn" href="fn.suq_sin.html" title="fn plotpy::suq_sin">suq_sin</a></div><div class="desc docblock-short">Implements the superquadric function involving sin(x)</div></li></ul><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.StrError.html" title="type plotpy::StrError">StrError</a></div><div class="desc docblock-short">Defines a type alias for the error type as a static string</div></li></ul></section></div></main></body></html> |