Skip to content

Commit

Permalink
Merge branch 'has2k1:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
fkgruber authored Jun 17, 2024
2 parents 05975dc + a3d893f commit 59703e1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
7 changes: 7 additions & 0 deletions doc/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ title: Changelog
- The `family`, `fontstyle` and `fontweight` parameters of
[](:class:`~plotnine.geom_text`) are now aesthetics ({{< issue 790 >}}).

- plotnine now responds to the `fig-width`, `fig-height` and `fig-format`
settings in the meta section of a quarto document.

### New Features

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

### Bug Fixes

- Fix layers 3 and above not to overlap the axis lines if there are any
({{< issue 798 >}}).

## v0.13.6
(2024-05-09)
Expand Down
37 changes: 35 additions & 2 deletions plotnine/options.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import typing
import os
from typing import TYPE_CHECKING

if typing.TYPE_CHECKING:
if TYPE_CHECKING:
from typing import Any, Literal, Optional, Type

from plotnine import theme
Expand Down Expand Up @@ -105,3 +106,35 @@ def set_option(name: str, value: Any) -> Any:
old = d[name]
d[name] = value
return old


# Quarto sets environment variables for the figure dpi, size and format
# for the project or document.
#
# https://quarto.org/docs/computations/execution-options.html#figure-options
#
# If we are in quarto, we read those and make them the default values for
# the options.
# Note that, reading the variables and setting them in a context manager
# cannot not work since the option values would be set after the original
# defaults have been used by the theme.
if "QUARTO_FIG_WIDTH" in os.environ:

def _set_options_from_quarto():
"""
Set options from quarto
"""
global dpi, figure_size, figure_format

dpi = int(os.environ["QUARTO_FIG_DPI"])
figure_size = (
float(os.environ["QUARTO_FIG_WIDTH"]),
float(os.environ["QUARTO_FIG_HEIGHT"]),
)

# quarto verifies the format
# If is retina, it doubles the original dpi and changes the
# format to png
figure_format = os.environ["QUARTO_FIG_FORMAT"] # pyright: ignore

_set_options_from_quarto()
14 changes: 12 additions & 2 deletions plotnine/themes/themeable.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,13 @@ class axis_line_x(themeable):

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

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

def apply_ax(self, ax: Axes):
super().apply_ax(ax)
properties = self.properties
# MPL has a default zorder of 2.5 for spines
# so layers 3+ would be drawn on top of the spines
if "zorder" not in properties:
properties["zorder"] = 10000
ax.spines["right"].set_visible(False)
ax.spines["left"].set(**self.properties)
ax.spines["left"].set(**properties)

def blank_ax(self, ax: Axes):
super().blank_ax(ax)
Expand Down

0 comments on commit 59703e1

Please sign in to comment.