Skip to content

Setting minor ticks with SecondaryAxis #16390

Closed
@jstoppelman

Description

@jstoppelman

Bug report

Bug summary

Hello, I am unable to set minor ticks without labels using SecondaryAxis. Using SecondaryAxis.set_ticks(ticks, minor=True) only makes major tick marks.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator

def forw(x):
    return x/5.2

def rev(x):
    return x*5.2

p_xax = [i for i in range(0,21,5)]
p_yax = [i for i in range(0,13,3)]
plt.scatter(p_xax, p_yax, color='black')
plt.xlabel("Main xaxis")
plt.ylabel("Main yaxis")
plt.xlim(0,20)
plt.ylim(0,15)
plt.xticks(np.arange(0,21,5))
plt.yticks(np.arange(0,16,3))

ax = plt.gca()
ax.xaxis.set_minor_locator(AutoMinorLocator(2))
ax.yaxis.set_minor_locator(AutoMinorLocator(2))

sec = ax.secondary_xaxis('top', functions=(forw, rev))
sec.set_xlabel(r"Secondary xaxis")
sec.set_ticks(np.arange(0,3.5,1), minor=True)
plt.savefig("test_plot.png")

Actual outcome

test_plot

Expected outcome

I would like to have the "top xaxis" look like the bottom one, with minor ticks between the major ticks without labels. The plot shown makes minor ticks have the same size as the major ones, and I'm not sure how to turn off labels in the current code.

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 3.1.1 from conda
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.6.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions