Skip to content

Commit 68e7532

Browse files
committed
add ScatterPolar
1 parent 3d06377 commit 68e7532

File tree

3 files changed

+661
-1
lines changed

3 files changed

+661
-1
lines changed

plotly/examples/basic_charts.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use plotly::common::{
33
ColorScale, ColorScalePalette, DashType, Fill, Font, Line, LineShape, Marker, Mode, Title,
44
};
55
use plotly::layout::{Axis, BarMode, Layout, Legend, TicksDirection};
6-
use plotly::{Bar, NamedColor, Plot, Rgb, Rgba, Scatter};
6+
use plotly::{Bar, NamedColor, Plot, Rgb, Rgba, Scatter, ScatterPolar};
77
use rand_distr::{Distribution, Normal, Uniform};
88

99
// Scatter Plots
@@ -82,6 +82,27 @@ fn bubble_scatter_plots(show: bool) {
8282
println!("{}", plot.to_inline_html(Some("bubble_scatter_plots")));
8383
}
8484

85+
fn polar_scatter_plot(show: bool) {
86+
let n: usize = 400;
87+
let theta: Vec<f64> = linspace(0., 360., n).collect();
88+
let r: Vec<f64> = theta
89+
.iter()
90+
.map(|x| {
91+
let x = x / 360. * core::f64::consts::TAU;
92+
let x = x.cos();
93+
1. / 8. * (63. * x.powf(5.) - 70. * x.powf(3.) + 15. * x).abs()
94+
})
95+
.collect();
96+
97+
let trace = ScatterPolar::new(theta, r).mode(Mode::Lines);
98+
let mut plot = Plot::new();
99+
plot.add_trace(trace);
100+
if show {
101+
plot.show();
102+
}
103+
println!("{}", plot.to_inline_html(Some("polar_scatter_plot")));
104+
}
105+
85106
fn data_labels_hover(show: bool) {
86107
let trace1 = Scatter::new(vec![1, 2, 3, 4, 5], vec![1, 6, 3, 6, 1])
87108
.mode(Mode::Markers)
@@ -594,6 +615,7 @@ fn main() -> std::io::Result<()> {
594615
simple_scatter_plot(true);
595616
line_and_scatter_plots(true);
596617
bubble_scatter_plots(true);
618+
polar_scatter_plot(true);
597619
data_labels_hover(true);
598620
data_labels_on_the_plot(true);
599621
colored_and_styled_scatter_plot(true);

plotly/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod heat_map;
2121
pub mod histogram;
2222
pub mod ohlc;
2323
pub mod scatter;
24+
pub mod scatter_polar;
2425
pub mod surface;
2526

2627
pub use crate::layout::Layout;
@@ -35,6 +36,7 @@ pub use crate::heat_map::HeatMap;
3536
pub use crate::histogram::Histogram;
3637
pub use crate::ohlc::Ohlc;
3738
pub use crate::scatter::Scatter;
39+
pub use crate::scatter_polar::ScatterPolar;
3840
pub use crate::surface::Surface;
3941

4042
pub use crate::common::color::NamedColor;

0 commit comments

Comments
 (0)