Open
Description
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:
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)
plt.show()
Activity
tzeitim commentedon Mar 21, 2023
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.timhoffm commentedon Sep 25, 2024
This is a general issue with the determination of text sizes (related #13044), as can seen by drawing boxes around the tick labels:
ksunden commentedon Sep 25, 2024
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)