Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axis ticks hidden behind histogram despite sufficiently large zorder #819

Open
jndrf opened this issue Aug 31, 2020 · 1 comment
Open

Axis ticks hidden behind histogram despite sufficiently large zorder #819

jndrf opened this issue Aug 31, 2020 · 1 comment

Comments

@jndrf
Copy link

jndrf commented Aug 31, 2020

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
@jndrf
Copy link
Author

jndrf commented Sep 1, 2020

I found a workaround: If one explicitly specifies the zorder of the histograms, the axis ticks aren't covered -- even if one does not specify the zorder of the ticks.

rootpy.plotting.root2matplotlib.hist(h, color='red', axes=ax, zorder=1)
ax.tick_params(which='both', direction='in')

rootpy_workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant