Skip to content

Axis ticks are not aligned by baseline #4115

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy