Allow to use a non fixed axes formatter
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- data-visualization
Research direction
Start by reading the fixed formatter in plotnine/_mpl/ticker.py and how it is applied from plotnine/facets/facet.py. Trace ggplot's draw flow and the interaction between plot.draw(), plot.show(), and the axes exposed by the figure. Done should allow users to apply Matplotlib locators and formatters such as AutoLocator and EngFormatter so ticks update appropriately when zooming, without monkey-patching ggplot.
Written by the indexing model from the issue text.
Description
Hello,
I am a Python user that came from using plain Matplotlib (not an R user switching to Python). I noticed today that if I take e.g this plot:
And zoom in:
The x & y ticks are fixed! I tried to figure out from reading the code whether I can change this, and I encountered this in plotnine's code:
Which is used here:
I am not sure whether the graphics grammar allows modifying this behavior, but I won't mind doing it via Matplotlib's native functions. However, that turned out to be hard and frustrating, as plot.draw() returns a figure, but I can't modify the axes of it. Here's something I tried:
from matplotlib.ticker import (
EngFormatter,
AutoLocator,
)
for ax in plot.draw(show=False).axes:
ax.xaxis.set_major_locator(AutoLocator())
ax.yaxis.set_major_locator(AutoLocator())
ax.xaxis.set_major_formatter(EngFormatter())
ax.yaxis.set_major_formatter(EngFormatter())
plot.show() # Also tried `matplotlib.pyplot.show()` here too.
And it doesn't show anything. As a side note, this made me wonder: What is the benefit in returning the figure if it cannot be manipulated afterwards with plain-old Matplotlib? This is related of course to:
Anyway, I managed to workaround this with the following ugly monkey-patching of ggplot class:
from matplotlib.ticker import (
EngFormatter,
AutoLocator,
)
ggplot_original__draw_breaks_and_labels = ggplot._draw_breaks_and_labels
def ggplot__draw_breaks_and_labels_with_my_ax_manipulation(self):
ggplot_original__draw_breaks_and_labels(self)
for ax in self.axs:
ax.xaxis.set_major_formatter(EngFormatter(unit="Hz"))
ax.yaxis.set_major_formatter(EngFormatter(unit="Hz"))
ax.xaxis.set_major_locator(AutoLocator())
ax.yaxis.set_major_locator(AutoLocator())
ggplot._draw_breaks_and_labels = ggplot__draw_breaks_and_labels_with_my_ax_manipulation
Not sure why the ticks are located in fixed positions just due to the major_formatter set above, but for sure the AutoLocator is needed too.
- Dominant language
- Python
- Stars
- 4.8k
- Forks
- 269
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from has2k1/plotnine
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Feature request: add rotation_mode param to geom_textPossibly taken A pull request linked to this issue is open or already merged. OpenFeature
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
position_dodge2() leaves nested rectangles overlappingPossibly taken @MahnoorAhmed999 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
-
Enhancement
Difficulty 3/5 Half a day Newbie friendliness 55/100
-
Discussion
Difficulty 5/5 Over a week Newbie friendliness 30/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
plone/plone.observability#114 ·
Maintainers usually reply within 1 day
-
area:docs type:docs
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
jejjohnson/gauss_flows#246 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openvax/varcode#824 · 1 comment ·
Maintainers usually reply within 1 day
-
netbox status: needs triage type: feature
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
netbox-community/netbox#23868 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
emeryberger/CSrankings#15757 ·
Maintainers usually reply within 9 days