Skip to content

Commit 75bac9f

Browse files
committed
Add plot_annotation tests
1 parent 6a8ec93 commit 75bac9f

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed
15.6 KB
Loading
15.2 KB
Loading
15.2 KB
Loading

tests/test_plot_composition.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
)
1111
from plotnine._utils.yippie import geom as g
1212
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
1414

1515

1616
def test_basic_horizontal_align_resize():
@@ -328,3 +328,72 @@ def test_plot_layout_byrow():
328328

329329
p = (p1 + p2 + p3 + p4) + plot_layout(nrow=3, byrow=False)
330330
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

Comments
 (0)