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
I would like to place the tick labels snug with the ticks. Setting pad=0 is not enough: There is still a distance between the label and the tick. This is with matplotlib 3.4.2. MWE:
I workaround I used is to set the pad to negative values. I am guessing that the origin of the vector is at the geometric center. Perhaps if it can be controlled via a 'left-justified' of 'right-justified' the label could be better controlled.
This is a general issue with the determination of text sizes (related #13044), as can seen by drawing boxes around the tick labels:
import matplotlib.pyplot as plt
import numpy as np
x = np.array([0.0, 1.0])
y = x
plt.plot(x, y)
ax = plt.gca()
ax.tick_params(axis='both', which='major', pad=0, length=10, width=20)
box_style = dict(facecolor='None', edgecolor='red', pad=0)
for tick in ax.xaxis.get_major_ticks():
tick.label1.set_bbox(box_style)
for tick in ax.yaxis.get_major_ticks():
tick.label1.set_bbox(box_style)
plt.show()
You can get at least closer by using text.usetex=True, as text rendered using LaTeX uses a relatively tight bounding box. (Quick test was still not perfect, but only a pixel or two between)
It is an imperfect solution, for several reasons, but noting here just in case someone finds it useful.
One of the more subtle reasons it is imperfect is because the reason this may work for this usecase is actually the cause of other problems such as #28766 and #24166, where positioning certain rendered text artifacts is hard to contain (e.g. cutting out whitespace or problems with vertical position of dashes)
I would like to place the tick labels snug with the ticks. Setting
pad=0
is not enough: There is still a distance between the label and the tick. This is with matplotlib 3.4.2. MWE:The text was updated successfully, but these errors were encountered: