You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There currently isn't any method of controlling where offset text for an axis gets placed. This causes problems when changing tick locations (e.g. tick_top and tick_right).
Axis.offset_text_position appears to have been intended to be the control, but changing ax.xaxis.offset_text_position and ax.yaxis.offset_text_position has no effect. Furthermore, there doesn't appear to be a code path where offset_text_position is used, or any other mechanism for changing the offset text's position. XAxis._update_offset_text_position (and the equivalent in YAxis) will need to be updated to take this into account.
Consider the following example:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 1e8)
y = np.exp(x**0.2)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.xaxis.tick_top()
ax.yaxis.tick_right()
plt.show()
In this case, the 1e17 corresponds to the y-axis, while the 1e8 corresponds to the x-axis. Ideally, these should be aligned so that it's clear which axis they correspond to.
For the y-axis, we can move the offset text to the left-hand side, but it will still be in a position that overlaps with the x-axis's ticklabels. Regardless, there's no corresponding method for the x-axis. As an example:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 1e8)
y = np.exp(x**0.2)
fig, ax = plt.subplots()
ax.plot(x, y)
ax.xaxis.tick_top()
ax.yaxis.tick_right()
ax.yaxis.set_offset_position("right")
plt.show()
I do not beleive so. This needs a champion to pick up the proposed patch, write some tests for it, write some documentation for it and get the PR through.
The following patch seems to work for that case, but I would need to investigate further if it might break something or the change should go elsewhere:
diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py
index 56d4e6b77d..773a95ad2a 100644
--- a/lib/matplotlib/axis.py+++ b/lib/matplotlib/axis.py@@ -2558,8 +2559,7 @@ class YAxis(Axis):
self.offsetText.set(
x=0, y=0.5,
verticalalignment='baseline', horizontalalignment='left',
- transform=mtransforms.blended_transform_factory(- self.axes.transAxes, mtransforms.IdentityTransform()),+ transform=mtransforms.IdentityTransform(),
fontsize=mpl.rcParams['ytick.labelsize'],
color=tick_color
)
@@ -2646,6 +2646,8 @@ class YAxis(Axis):
bbox = self.axes.spines['outline'].get_window_extent()
else:
bbox = self.axes.bbox
+ spine_bbox = self.axes.spines[self.offsetText.get_ha()].get_window_extent()+ x = spine_bbox.x0
top = bbox.ymax
self.offsetText.set_position(
(x, top + self.OFFSETTEXTPAD * self.figure.dpi / 72)
It also probably needs to be replicated for XAxis.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
joferkington commentedon May 26, 2015
As an example of one possible implementation (using monkey-patching to demonstrate the proof-of-concept instead of a "full" pull request):
soupault commentedon Jan 14, 2016
This also affects the case when several axes are placed on the same side of the plot.
For example,
tacaswell commentedon Jan 14, 2016
@soupault Any chance we could get you to turn @joferkington 's patch into a PR?
soupault commentedon Jan 26, 2016
@tacaswell Sorry, I'm not familiar with the source code at all. I can start to work on the PR in free time, but can't promise it any time soon.
maxnoe commentedon May 18, 2017
This is still an issue in matplotlib 2.0
Any news on this?
efojs commentedon Feb 7, 2020
Also with multiple axis. Either with parasite axes (demo 1, demo 2) or with spines.
E.g. here

ylimof Velocity is set to6.5e7:Is there any built-in solution other than
_update_offset_text_positionandset_visible(False)?v3.1.2
tacaswell commentedon Feb 7, 2020
I do not beleive so. This needs a champion to pick up the proposed patch, write some tests for it, write some documentation for it and get the PR through.
3 remaining items
oscargus commentedon Apr 13, 2023
Current status:
Since there is a patch that may solve it (although it can require a bit of work to adapt), and it is still a bit of an issue I reopen it.
QuLogic commentedon Dec 1, 2023
See https://discourse.matplotlib.org/t/overlapping-of-scientific-notation-exponents-with-twin-axes/24145/4?u=qulogic for the same problem with twinned Axes and offset Spines.
The following patch seems to work for that case, but I would need to investigate further if it might break something or the change should go elsewhere:
It also probably needs to be replicated for
XAxis.github-actions commentedon Dec 2, 2024
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
ctjlewis commentedon Feb 15, 2025
This is still an issue.