()
| 141 | } |
| 142 | |
| 143 | fn 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)) |
no test coverage detected