MCPcopy Create free account
hub / github.com/alceal/plotlars / irregular_grid_example

Function irregular_grid_example

crates/plotlars/examples/plotly_subplot_grid.rs:143–239  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

141}
142
143fn irregular_grid_example() {
144 let dataset1 = CsvReader::new("data/penguins.csv")
145 .finish()
146 .unwrap()
147 .lazy()
148 .select([
149 col("species"),
150 col("sex").alias("gender"),
151 col("flipper_length_mm").cast(DataType::Int16),
152 col("body_mass_g").cast(DataType::Int16),
153 ])
154 .collect()
155 .unwrap();
156
157 let axis = Axis::new()
158 .show_line(true)
159 .show_grid(true)
160 .value_thousands(true)
161 .tick_direction(TickDirection::OutSide);
162
163 let plot1 = Histogram::builder()
164 .data(&dataset1)
165 .x("body_mass_g")
166 .group("species")
167 .opacity(0.5)
168 .colors(vec![Rgb(255, 165, 0), Rgb(147, 112, 219), Rgb(46, 139, 87)])
169 .plot_title(Text::from("Histogram").x(0.0).y(1.35).size(14))
170 .x_title(Text::from("body mass (g)").x(0.94).y(-0.35))
171 .y_title(Text::from("count").x(-0.062).y(0.83))
172 .x_axis(&axis)
173 .y_axis(&axis)
174 .legend_title(Text::from("species"))
175 .legend(&Legend::new().x(0.87).y(1.2))
176 .build();
177
178 let dataset2 = CsvReader::new("data/stock_prices.csv").finish().unwrap();
179
180 let increasing = Direction::new()
181 .line_color(Rgb(0, 200, 100))
182 .line_width(0.5);
183
184 let decreasing = Direction::new()
185 .line_color(Rgb(200, 50, 50))
186 .line_width(0.5);
187
188 let plot2 = CandlestickPlot::builder()
189 .data(&dataset2)
190 .dates("date")
191 .open("open")
192 .high("high")
193 .low("low")
194 .close("close")
195 .increasing(&increasing)
196 .decreasing(&decreasing)
197 .whisker_width(0.1)
198 .plot_title(Text::from("Candlestick").x(0.0).y(1.35).size(14))
199 .y_title(Text::from("price ($)").x(-0.06).y(0.76))
200 .y_axis(&Axis::new().show_axis(true).show_grid(true))

Callers 1

mainFunction · 0.85

Calls 15

RgbClass · 0.85
value_thousandsMethod · 0.80
show_gridMethod · 0.80
show_lineMethod · 0.80
sizeMethod · 0.80
show_axisMethod · 0.80
tick_stepMethod · 0.80
separate_thousandsMethod · 0.80
titleMethod · 0.80
h_gapMethod · 0.80
v_gapMethod · 0.80
colsMethod · 0.80

Tested by

no test coverage detected