|
35 | 35 | theme_xkcd, |
36 | 36 | ) |
37 | 37 | from plotnine.data import mtcars |
38 | | -from plotnine.themes.themeable import panel_border |
| 38 | +from plotnine.coords.coord_cartesian import coord_cartesian |
| 39 | +from plotnine.themes.themeable import panel_border, themeable |
39 | 40 |
|
40 | 41 | LT_MPL310 = version.parse(mpl.__version__) < version.parse("3.10") |
41 | 42 | IS_CI = bool(os.environ.get("CI")) |
@@ -124,6 +125,48 @@ def test_blank_panel_border_hides_polar_spine(): |
124 | 125 | plt.close(fig) |
125 | 126 |
|
126 | 127 |
|
| 128 | +def test_extension_themeable_applies_from_theme_kwargs(): |
| 129 | + class test_extension_panel_facecolor(themeable): |
| 130 | + def apply_ax(self, ax): |
| 131 | + super().apply_ax(ax) |
| 132 | + ax.set_facecolor(self.properties["value"]) |
| 133 | + |
| 134 | + p = ( |
| 135 | + ggplot(mtcars, aes(x="wt", y="mpg")) |
| 136 | + + geom_point() |
| 137 | + + theme(test_extension_panel_facecolor="red") |
| 138 | + ) |
| 139 | + |
| 140 | + fig = p.draw() |
| 141 | + try: |
| 142 | + assert fig.axes[0].get_facecolor() == (1.0, 0.0, 0.0, 1.0) |
| 143 | + finally: |
| 144 | + plt.close(fig) |
| 145 | + |
| 146 | + |
| 147 | +def test_coord_can_read_extension_themeable(): |
| 148 | + class test_extension_coord_title(themeable): |
| 149 | + pass |
| 150 | + |
| 151 | + class coord_reads_themeable(coord_cartesian): |
| 152 | + def setup_ax(self, ax, panel_params, theme): |
| 153 | + super().setup_ax(ax, panel_params, theme) |
| 154 | + ax.set_title(theme.getp("test_extension_coord_title")) |
| 155 | + |
| 156 | + p = ( |
| 157 | + ggplot(mtcars, aes(x="wt", y="mpg")) |
| 158 | + + geom_point() |
| 159 | + + coord_reads_themeable() |
| 160 | + + theme(test_extension_coord_title="coord themeable") |
| 161 | + ) |
| 162 | + |
| 163 | + fig = p.draw() |
| 164 | + try: |
| 165 | + assert fig.axes[0].get_title() == "coord themeable" |
| 166 | + finally: |
| 167 | + plt.close(fig) |
| 168 | + |
| 169 | + |
127 | 170 | def test_element_line_dashed_capstyle(): |
128 | 171 | p = ggplot(mtcars, aes(x="wt", y="mpg")) + theme( |
129 | 172 | panel_grid=element_line( |
|
0 commit comments