Skip to content

Commit 59703e1

Browse files
authored
Merge branch 'has2k1:main' into main
2 parents 05975dc + a3d893f commit 59703e1

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

doc/changelog.qmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ title: Changelog
1010
- The `family`, `fontstyle` and `fontweight` parameters of
1111
[](:class:`~plotnine.geom_text`) are now aesthetics ({{< issue 790 >}}).
1212

13+
- plotnine now responds to the `fig-width`, `fig-height` and `fig-format`
14+
settings in the meta section of a quarto document.
15+
1316
### New Features
1417

1518
- [](:class:`~plotnine.geom_text`) has gained new aesthetics
1619
`fontvariant` and `fontstretch`.
1720

21+
### Bug Fixes
22+
23+
- Fix layers 3 and above not to overlap the axis lines if there are any
24+
({{< issue 798 >}}).
1825

1926
## v0.13.6
2027
(2024-05-09)

plotnine/options.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3-
import typing
3+
import os
4+
from typing import TYPE_CHECKING
45

5-
if typing.TYPE_CHECKING:
6+
if TYPE_CHECKING:
67
from typing import Any, Literal, Optional, Type
78

89
from plotnine import theme
@@ -105,3 +106,35 @@ def set_option(name: str, value: Any) -> Any:
105106
old = d[name]
106107
d[name] = value
107108
return old
109+
110+
111+
# Quarto sets environment variables for the figure dpi, size and format
112+
# for the project or document.
113+
#
114+
# https://quarto.org/docs/computations/execution-options.html#figure-options
115+
#
116+
# If we are in quarto, we read those and make them the default values for
117+
# the options.
118+
# Note that, reading the variables and setting them in a context manager
119+
# cannot not work since the option values would be set after the original
120+
# defaults have been used by the theme.
121+
if "QUARTO_FIG_WIDTH" in os.environ:
122+
123+
def _set_options_from_quarto():
124+
"""
125+
Set options from quarto
126+
"""
127+
global dpi, figure_size, figure_format
128+
129+
dpi = int(os.environ["QUARTO_FIG_DPI"])
130+
figure_size = (
131+
float(os.environ["QUARTO_FIG_WIDTH"]),
132+
float(os.environ["QUARTO_FIG_HEIGHT"]),
133+
)
134+
135+
# quarto verifies the format
136+
# If is retina, it doubles the original dpi and changes the
137+
# format to png
138+
figure_format = os.environ["QUARTO_FIG_FORMAT"] # pyright: ignore
139+
140+
_set_options_from_quarto()

plotnine/themes/themeable.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,13 @@ class axis_line_x(themeable):
893893

894894
def apply_ax(self, ax: Axes):
895895
super().apply_ax(ax)
896+
properties = self.properties
897+
# MPL has a default zorder of 2.5 for spines
898+
# so layers 3+ would be drawn on top of the spines
899+
if "zorder" not in properties:
900+
properties["zorder"] = 10000
896901
ax.spines["top"].set_visible(False)
897-
ax.spines["bottom"].set(**self.properties)
902+
ax.spines["bottom"].set(**properties)
898903

899904
def blank_ax(self, ax: Axes):
900905
super().blank_ax(ax)
@@ -916,8 +921,13 @@ class axis_line_y(themeable):
916921

917922
def apply_ax(self, ax: Axes):
918923
super().apply_ax(ax)
924+
properties = self.properties
925+
# MPL has a default zorder of 2.5 for spines
926+
# so layers 3+ would be drawn on top of the spines
927+
if "zorder" not in properties:
928+
properties["zorder"] = 10000
919929
ax.spines["right"].set_visible(False)
920-
ax.spines["left"].set(**self.properties)
930+
ax.spines["left"].set(**properties)
921931

922932
def blank_ax(self, ax: Axes):
923933
super().blank_ax(ax)

0 commit comments

Comments
 (0)