Skip to content

Axis ticks are not aligned by baseline #4115

Closed as not planned
Closed as not planned
@jowr

Description

@jowr

Hi, it looks like the PGF backend defaults to top-align tick labels without accounting for the height of the letters. This works without problems with the PDF backend, also using Tex to render text does not make a difference.
using this Python code:

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(2,2))
ax = fig.add_subplot(111)
ax.plot([1,2],[5,7])
ax.set_xticks([1,2])
ax.set_xticklabels(["up","down"])
ax.set_xlim([0,3]) # get the ticks closer together
plt.tight_layout()
fig.savefig("ticks_std.pdf")
fig.savefig("ticks_std.pgf")
for lab in ax.xaxis.get_ticklabels():
    lab.set_verticalalignment("baseline")
fig.savefig("ticks_base.pdf")
fig.savefig("ticks_base.pgf")
for lab in ax.xaxis.get_ticklabels():
    lab.set_verticalalignment("top")
fig.savefig("ticks_top.pdf")
fig.savefig("ticks_top.pgf")

... and this Tex document:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tabular}{ccc}
\input{ticks_std.pgf} & \input{ticks_base.pgf} & \input{ticks_top.pgf} \\
\includegraphics{ticks_std.pdf} & \includegraphics{ticks_base.pdf} & \includegraphics{ticks_top.pdf}
\end{tabular}
\end{document} 

produces this:
ticks

One possible solution could be to use the baseline alignment with some additional padding depending on the font size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend: pgfstatus: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions