|
10 | 10 | ) |
11 | 11 | from plotnine._utils.yippie import geom as g |
12 | 12 | from plotnine._utils.yippie import legend, plot, rotate, tag |
13 | | -from plotnine.composition._plot_layout import plot_layout |
| 13 | +from plotnine.composition import plot_annotation, plot_layout |
14 | 14 |
|
15 | 15 |
|
16 | 16 | def test_basic_horizontal_align_resize(): |
@@ -328,3 +328,72 @@ def test_plot_layout_byrow(): |
328 | 328 |
|
329 | 329 | p = (p1 + p2 + p3 + p4) + plot_layout(nrow=3, byrow=False) |
330 | 330 | assert p == "plot_layout_byrow" |
| 331 | + |
| 332 | + |
| 333 | +def test_plot_annotation_position_plot(): |
| 334 | + p1 = plot.red |
| 335 | + p2 = plot.green |
| 336 | + p3 = plot.blue |
| 337 | + |
| 338 | + th1 = theme( |
| 339 | + plot_title=element_text(color="red"), |
| 340 | + plot_subtitle=element_text(color="green"), |
| 341 | + plot_caption=element_text(color="blue"), |
| 342 | + plot_title_position="plot", |
| 343 | + ) |
| 344 | + ann = plot_annotation( |
| 345 | + title="The Title of the Red, Green and Blue Composition", |
| 346 | + subtitle="The subtitle of the red, green and blue composition", |
| 347 | + caption="The caption of the red, green and blue composition.", |
| 348 | + theme=th1, |
| 349 | + ) |
| 350 | + |
| 351 | + p = ((p1 | p2) / p3) + ann |
| 352 | + assert p == "plot_annotation_position_plot" |
| 353 | + |
| 354 | + |
| 355 | +def test_plot_annotation_position_panel(): |
| 356 | + p1 = plot.red |
| 357 | + p2 = plot.green |
| 358 | + p3 = plot.blue |
| 359 | + th = theme( |
| 360 | + plot_title=element_text(color="red"), |
| 361 | + plot_subtitle=element_text(color="green"), |
| 362 | + plot_caption=element_text(color="blue"), |
| 363 | + plot_title_position="panel", |
| 364 | + ) |
| 365 | + ann = plot_annotation( |
| 366 | + title="The Title of the Red, Green and Blue Composition", |
| 367 | + subtitle="The subtitle of the red, green and blue composition", |
| 368 | + caption="The caption of the red, green and blue composition.", |
| 369 | + theme=th, |
| 370 | + ) |
| 371 | + |
| 372 | + p = ((p1 | p2) / p3) + ann |
| 373 | + assert p == "plot_annotation_position_panel" |
| 374 | + |
| 375 | + |
| 376 | +def test_plot_annotation_addition(): |
| 377 | + p1 = plot.red |
| 378 | + p2 = plot.green |
| 379 | + p3 = plot.blue |
| 380 | + p4 = plot.yellow |
| 381 | + |
| 382 | + th = theme( |
| 383 | + plot_title=element_text(color="red"), |
| 384 | + plot_subtitle=element_text(color="green"), |
| 385 | + plot_caption=element_text(color="blue"), |
| 386 | + plot_title_position="panel", |
| 387 | + ) |
| 388 | + ann = plot_annotation( |
| 389 | + title="The Title of the RGBY Composition", |
| 390 | + subtitle="The subtitle of the RGBY composition", |
| 391 | + caption="The caption of the RGBY composition.", |
| 392 | + theme=th, |
| 393 | + ) |
| 394 | + |
| 395 | + p = ((p1 / p2) + (p3 | p4)) + ann |
| 396 | + p_alt = ((p1 / p2) + ann) + (p3 | p4) |
| 397 | + |
| 398 | + assert p == "plot_annotation_addition" |
| 399 | + assert p_alt == "plot_annotation_addition" |
0 commit comments