@@ -3,7 +3,7 @@ use plotly::common::{
3
3
ColorScale , ColorScalePalette , DashType , Fill , Font , Line , LineShape , Marker , Mode , Title ,
4
4
} ;
5
5
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 } ;
7
7
use rand_distr:: { Distribution , Normal , Uniform } ;
8
8
9
9
// Scatter Plots
@@ -82,6 +82,27 @@ fn bubble_scatter_plots(show: bool) {
82
82
println ! ( "{}" , plot. to_inline_html( Some ( "bubble_scatter_plots" ) ) ) ;
83
83
}
84
84
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
+
85
106
fn data_labels_hover ( show : bool ) {
86
107
let trace1 = Scatter :: new ( vec ! [ 1 , 2 , 3 , 4 , 5 ] , vec ! [ 1 , 6 , 3 , 6 , 1 ] )
87
108
. mode ( Mode :: Markers )
@@ -594,6 +615,7 @@ fn main() -> std::io::Result<()> {
594
615
simple_scatter_plot ( true ) ;
595
616
line_and_scatter_plots ( true ) ;
596
617
bubble_scatter_plots ( true ) ;
618
+ polar_scatter_plot ( true ) ;
597
619
data_labels_hover ( true ) ;
598
620
data_labels_on_the_plot ( true ) ;
599
621
colored_and_styled_scatter_plot ( true ) ;
0 commit comments