We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4ddb4e1 commit 89a9c6bCopy full SHA for 89a9c6b
2 files changed
examples/plot_types.rs
@@ -16,6 +16,7 @@ fn main() -> anyhow::Result<()> {
16
bar()?;
17
stem()?;
18
fill_between()?;
19
+ stackplot()?;
20
Ok(())
21
}
22
@@ -108,3 +109,22 @@ fn fill_between() -> anyhow::Result<()> {
108
109
fig.save().to_file(format!("{BASE}fill_between.pdf"))?;
110
111
112
+
113
+fn stackplot() -> anyhow::Result<()> {
114
+ use ndarray::{arr1, Axis, stack};
115
116
+ let x = Array1::range(0., 10., 2.);
117
+ let ay = arr1(&[1., 1.25, 2., 2.75, 3.]);
118
+ let by = arr1(&[1., 1., 1., 1., 1.]);
119
+ let cy = arr1(&[2., 1., 2., 1., 2.]);
120
+ let y = stack(Axis(0), &[ay.view(), by.view(), cy.view()]).unwrap();
121
122
+ let (fig, [[mut ax]]) = figure::subplots()?;
123
124
+ ax.stack(&x, &y).plot();
125
126
+ ax.set_xlim(0., 8.) .set_xticks((1..8).map(f64::from));
127
+ ax.set_ylim(0., 8.) .set_yticks((1..8).map(f64::from));
128
+ fig.save().to_file(format!("{BASE}stackplot.pdf"))?;
129
+ Ok(())
130
+}
src/axes.rs
@@ -282,6 +282,14 @@ impl Axes {
282
FillBetween::new(self, x, y1, y2)
283
284
285
+ pub fn stack<'a>(
286
+ &'a mut self,
287
+ x: &'a impl Vector<f64>,
288
+ y: &'a ndarray::Array2<f64>,
289
+ ) -> Stack<'a> {
290
+ Stack::new(self, x, y)
291
+ }
292
293
/// Set the title to `txt` for the Axes.
294
pub fn set_title(&mut self, txt: impl AsRef<str>) -> &mut Self {
295
meth!(self.ax, set_title, (txt.as_ref(),)).unwrap();
@@ -1204,6 +1212,35 @@ impl<'a> FillBetween<'a> {
1204
1212
1205
1213
1206
1214
1215
+pub struct Stack<'a> {
1216
+ axes: &'a Axes,
1217
+ x: &'a dyn Vector<f64>,
1218
+ y: &'a Array2<f64>,
1219
+ // FIXME: there are optional arguments.
1220
1221
1222
+impl<'a> Stack<'a> {
1223
+ fn new(
1224
1225
1226
1227
+ ) -> Self {
1228
+ Self { axes, x, y }
1229
1230
1231
+ pub fn plot(self) {
1232
+ Python::attach(|py| {
1233
+ let x = self.x.to_pyvector(py);
1234
+ let y = self.y.to_pyarray(py);
1235
+ self.axes.ax.bind(py)
1236
+ .call_method(intern!(py, "stackplot"),
1237
+ (x, y),
1238
+ None)
1239
+ .unwrap();
1240
+ })
1241
1242
1243
1207
1244
pub struct QuadContourSet {
1208
1245
contours: Py<PyAny>,
1209
1246
0 commit comments