Skip to content

Axis ticks hidden behind histogram despite sufficiently large zorder #819

@jndrf

Description

@jndrf

Hi all,

I am using the root2matplotlib module to plot root histograms. I would like to have the ticks on the inner side of the axis, but they are covered by the histogram. Specifying a large value for zorder does not solve the problem. Note that the green line has a smaller zorder value than the ticks, yet it is shown on top of the histogram.

from __future__ import division, print_function

import matplotlib
import matplotlib.pyplot as plt

import rootpy.io
import rootpy.plotting
import rootpy.plotting.root2matplotlib

f = rootpy.io.root_open('samplehistogram.root')
h = f['h']

fig, ax = plt.subplots(1, 1)

rootpy.plotting.root2matplotlib.hist(h, color='red', axes=ax)
ax.tick_params(which='both', direction='in', zorder=10)
ax.axvline(0, color='green', linestyle='--', zorder=5)
plt.tight_layout()
fig.show()

samplehistogram.root.gz

rootpy

As a sanity check, this works as intended in matplotlib:

from __future__ import division, print_function

import numpy as np
import numpy.random 
import matplotlib
import matplotlib.pyplot as plt

numbers = np.random.rand(50, 1)

fig, ax = plt.subplots(1, 1)

ax.hist(numbers, histtype='stepfilled')
ax.tick_params(which='both', direction='in')

fig.show()

mpl

I found the unrelated #537, but the picture therein shows the ticks on the inside in front of the histograms. When I run the code now, the ticks are on the outside. If I manually place them on the inside, the histograms overlays them.

Tested with

  • Python 2.7.16, matplotlib 2.2.4, rootpy 1.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions