Tick label alignment not working as described · Issue #13440 · matplotlib/matplotlib · GitHub
Skip to content

Tick label alignment not working as described #13440

Description

@oestfeldt

Bug report

Bug summary

I want to change the horizontal alignment of the tick labels on my y-axis. This page explains a method (the one-liner on the top of the page), which does not work.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
print("Matplitlib version: %s" % mpl.__version__)
 
x = np.logspace(-2,3)
y = 1 / (exp(1/x) - 1)

fig = plt.figure(1, figsize=(4, 4))
plt.loglog(x,y)
plt.xlabel('x')
plt.ylabel('y')
plt.tight_layout()

ax = plt.gca()
ax.yaxis.set_tick_params(horizontalalignment='left')

The code above is slightly longer than minimum, to motivate why I need to change the tick label alignment. The changing size of the exponent looks ugly when the labels are right-aligned.

Actual outcome

axislabelcentertest

Matplitlib version: 3.0.2
Traceback (most recent call last):

  File "<ipython-input-17-ff49df94c4af>", line 1, in <module>
    runfile('/home/christoffer/Dropbox/Div/axislabelcentertest.py', wdir='/home/christoffer/Dropbox/Div')

  File "/home/christoffer/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 668, in runfile
    execfile(filename, namespace)

  File "/home/christoffer/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/christoffer/Dropbox/Div/axislabelcentertest.py", line 16, in <module>
    ax.yaxis.set_tick_params(horizontalalignment='left')

  File "/home/christoffer/anaconda3/lib/python3.7/site-packages/matplotlib/axis.py", line 852, in set_tick_params
    kwtrans = self._translate_tick_kw(kw, to_init_kw=True)

  File "/home/christoffer/anaconda3/lib/python3.7/site-packages/matplotlib/axis.py", line 917, in _translate_tick_kw
    % (key, kwkeys))

ValueError: keyword horizontalalignment is not recognized; valid keywords are ['size', 'width', 'color', 'tickdir', 'pad', 'labelsize', 'labelcolor', 'zorder', 'gridOn', 'tick1On', 'tick2On', 'label1On', 'label2On', 'length', 'direction', 'left', 'bottom', 'right', 'top', 'labelleft', 'labelbottom', 'labelright', 'labeltop', 'labelrotation', 'grid_agg_filter', 'grid_alpha', 'grid_animated', 'grid_antialiased', 'grid_clip_box', 'grid_clip_on', 'grid_clip_path', 'grid_color', 'grid_contains', 'grid_dash_capstyle', 'grid_dash_joinstyle', 'grid_dashes', 'grid_drawstyle', 'grid_figure', 'grid_fillstyle', 'grid_gid', 'grid_in_layout', 'grid_label', 'grid_linestyle', 'grid_linewidth', 'grid_marker', 'grid_markeredgecolor', 'grid_markeredgewidth', 'grid_markerfacecolor', 'grid_markerfacecoloralt', 'grid_markersize', 'grid_markevery', 'grid_path_effects', 'grid_picker', 'grid_pickradius', 'grid_rasterized', 'grid_sketch_params', 'grid_snap', 'grid_solid_capstyle', 'grid_solid_joinstyle', 'grid_transform', 'grid_url', 'grid_visible', 'grid_xdata', 'grid_ydata', 'grid_zorder', 'grid_aa', 'grid_c', 'grid_ls', 'grid_lw', 'grid_mec', 'grid_mew', 'grid_mfc', 'grid_mfcalt', 'grid_ms', 'grid_aa', 'grid_c', 'grid_ls', 'grid_lw', 'grid_mec', 'grid_mew', 'grid_mfc', 'grid_mfcalt', 'grid_ms']

Expected outcome

I expect the alignment of the y-axis tick labels to change.

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 3.0.2
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.1
  • Jupyter version (if applicable):
  • Other libraries: Numpy

Installed via conda.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesstatus: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions