Skip to content

Add LayoutScene #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.5] - 2023-xx-xx
### Added
- [[#153](https://github.com/igiagkiozis/plotly/pull/153)] Added `LayoutScene`

## [0.8.4] - 2023-07-09
### Added
- [[#143](https://github.com/igiagkiozis/plotly/pull/143)] Widen version range of `askama`.
Expand Down
72 changes: 57 additions & 15 deletions examples/3d_charts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

use ndarray::Array;
use plotly::{
common::{ColorScale, ColorScalePalette, Marker, MarkerSymbol, Mode, Title},
layout::{Axis, Layout},
color::Rgb,
common::{ColorScale, ColorScalePalette, Font, Marker, MarkerSymbol, Mode, Title},
layout::{Axis, Camera, Layout, LayoutScene, Legend, Margin, ProjectionType},
Mesh3D, Plot, Scatter3D, Surface,
};

Expand All @@ -29,6 +30,7 @@ fn customized_scatter3d_plot() {
let sizelookup = z.clone();

let trace = Scatter3D::new(t.clone(), y.clone(), z.iter().map(|i| -i).collect())
.name("Helix 1")
.mode(Mode::Markers)
.marker(
Marker::new()
Expand All @@ -42,25 +44,65 @@ fn customized_scatter3d_plot() {
.color_scale(ColorScale::Palette(ColorScalePalette::Viridis)),
);

let trace2 = Scatter3D::new(t, z, y).mode(Mode::Markers).marker(
Marker::new()
.size_array(
sizelookup
.iter()
.map(|i| (i.abs() * 25f64) as usize)
.collect(),
)
.color_scale(ColorScale::Palette(ColorScalePalette::Viridis)),
);
let trace2 = Scatter3D::new(t, z, y)
.name("Helix 2")
.mode(Mode::Markers)
.marker(
Marker::new()
.size_array(
sizelookup
.iter()
.map(|i| (i.abs() * 25f64) as usize)
.collect(),
)
.color_scale(ColorScale::Palette(ColorScalePalette::Viridis)),
);

let mut plot = Plot::new();
plot.add_trace(trace);
plot.add_trace(trace2);

let background_color: Rgb = Rgb::new(70, 70, 70);
let front_color: Rgb = Rgb::new(255, 255, 255);

let layout = Layout::new()
.title("Helix".into())
.x_axis(Axis::new().title("x (A meaningful axis name goes here)".into()))
.y_axis(Axis::new().title(Title::new("This is the label of the Y axis")))
.z_axis(Axis::new().title("z Axis".into()));
.legend(Legend::new().x(0.9).y(0.9))
.font(Font::new().color(front_color))
.paper_background_color(background_color)
.scene(
LayoutScene::new()
.x_axis(
Axis::new()
.title("x (A meaningful axis name goes here)".into())
.tick_angle(0f64)
.grid_color(front_color)
.color(front_color),
)
.y_axis(
Axis::new()
.title(Title::new("This is the label of the Y axis"))
.tick_format(".1f")
.grid_color(front_color)
.color(front_color),
)
.z_axis(Axis::new().title("".into()).tick_values(vec![]))
.aspect_mode(plotly::layout::AspectMode::Manual)
.aspect_ratio((3.0, 1.0, 1.0).into())
.camera(
Camera::new()
.projection(ProjectionType::Orthographic.into())
.eye((0.0, 0.0, 1.0).into())
.up((0.0, 1.0, 0.0).into())
.center((0.0, 0.0, 0.0).into()),
)
.drag_mode(plotly::layout::DragMode3D::Pan)
.hover_mode(plotly::layout::HoverMode::Closest)
.background_color(background_color),
)
.margin(Margin::new().left(0).right(0).top(50).bottom(0))
.width(1000)
.height(500);
plot.set_layout(layout);

plot.show();
Expand Down
1 change: 1 addition & 0 deletions plotly/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ target/
.idea
Cargo.lock
gh-pages/
.vscode
Loading