Skip to content

Commit 1c13241

Browse files
author
naijim
authored
Merge branch 'main' into table-pr
2 parents aaabcc2 + a6fd29b commit 1c13241

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

examples/subplots/src/main.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#![allow(dead_code)]
22

3-
use plotly::common::{AxisSide, Font, Title};
4-
use plotly::layout::{Axis, GridPattern, Layout, LayoutGrid, Legend, RowOrder, TraceOrder};
3+
use plotly::common::{Anchor, AxisSide, Font, Title};
4+
use plotly::layout::{
5+
Annotation, Axis, GridPattern, Layout, LayoutGrid, Legend, RowOrder, TraceOrder,
6+
};
7+
use plotly::Configuration;
58
use plotly::{color::Rgb, Plot, Scatter};
6-
79
// Subplots
810
fn simple_subplot() {
911
let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1");
@@ -242,6 +244,46 @@ fn multiple_axes() {
242244
plot.show();
243245
}
244246

247+
fn many_subplots_with_titles() {
248+
let trace1 = Scatter::new(vec![1, 2], vec![4, 5]);
249+
250+
let number_of_plots = 10;
251+
252+
let mut plot = Plot::new();
253+
let mut layout = Layout::new()
254+
.grid(
255+
LayoutGrid::new()
256+
.rows(number_of_plots / 2)
257+
.columns(2)
258+
.pattern(GridPattern::Independent),
259+
)
260+
.height(number_of_plots * 200);
261+
262+
for i in 1..number_of_plots + 1 {
263+
plot.add_trace(
264+
trace1
265+
.clone()
266+
.y_axis(format!("y{}", i))
267+
.x_axis(format!("x{}", i)),
268+
);
269+
layout.add_annotation(
270+
Annotation::new()
271+
.y_ref(format!("y{} domain", i))
272+
.y_anchor(Anchor::Bottom)
273+
.y(1)
274+
.text(format!("Title {}", i))
275+
.x_ref(format!("x{} domain", i))
276+
.x_anchor(Anchor::Center)
277+
.x(0.5)
278+
.show_arrow(false),
279+
)
280+
}
281+
282+
plot.set_layout(layout);
283+
plot.set_configuration(Configuration::new().responsive(true));
284+
plot.show();
285+
}
286+
245287
fn main() {
246288
// Uncomment any of these lines to display the example.
247289

@@ -252,6 +294,7 @@ fn main() {
252294
// stacked_subplots();
253295
// stacked_subplots_with_shared_x_axis();
254296
// multiple_custom_sized_subplots();
297+
// many_subplots_with_titles();
255298

256299
// Multiple Axes
257300
// two_y_axes();

plotly/src/layout/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ pub struct Axis {
441441
#[serde(rename = "nticks")]
442442
n_ticks: Option<usize>,
443443

444+
#[serde(rename = "scaleanchor")]
445+
scale_anchor: Option<String>,
446+
444447
tick0: Option<f64>,
445448
dtick: Option<f64>,
446449

plotly_kaleido/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,15 @@ impl Kaleido {
138138
let p = p.to_str().unwrap();
139139
let p = String::from(p);
140140

141-
let process = Command::new(p.as_str())
141+
let mut process = Command::new(p.as_str())
142142
.current_dir(self.cmd_path.parent().unwrap())
143143
.args([
144144
"plotly",
145145
"--disable-gpu",
146146
"--allow-file-access-from-files",
147147
"--disable-breakpad",
148148
"--disable-dev-shm-usage",
149+
"--disable-software-rasterizer",
149150
"--single-process",
150151
])
151152
.stdin(Stdio::piped())
@@ -156,14 +157,14 @@ impl Kaleido {
156157

157158
{
158159
let plot_data = PlotData::new(plotly_data, format, width, height, scale).to_json();
159-
let mut process_stdin = process.stdin.unwrap();
160+
let mut process_stdin = process.stdin.take().unwrap();
160161
process_stdin
161162
.write_all(plot_data.as_bytes())
162163
.expect("couldn't write to Kaleido stdin");
163164
process_stdin.flush()?;
164165
}
165166

166-
let output_lines = BufReader::new(process.stdout.unwrap()).lines();
167+
let output_lines = BufReader::new(process.stdout.take().unwrap()).lines();
167168
for line in output_lines.map_while(Result::ok) {
168169
let res = KaleidoResult::from(line.as_str());
169170
if let Some(image_data) = res.result {

0 commit comments

Comments
 (0)