Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ title: Changelog

### Enhancements

- The `factor` function available when evaluating expressions in
[](:class:`~plotnine.aes`) now accepts a scalar value.

```python
ggplot(mtcars, aes("wt", "mpg", color="factor(4)")) + geom_point()
```

- Increased the default linespacing used by themes from `0.9` to `1.2`.
This gives multiline titles, subtitles and captions a better balance between looking compact and looking crumpled.

Expand Down
5 changes: 4 additions & 1 deletion plotnine/mapping/_eval_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


def factor(
values: Sequence[Any],
values: Sequence[Any] | float | str,
categories: Sequence[Any] | None = None,
ordered: bool | None = None,
) -> pd.Categorical:
Expand All @@ -48,6 +48,9 @@ def factor(
`categories` attribute (which in turn is the `categories` argument, if
provided).
"""
if isinstance(values, (int, float, str)):
values = [values]

return pd.Categorical(values, categories=categories, ordered=None) # pyright: ignore[reportReturnType]


Expand Down
Loading