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

Disabling (or adjusting) border ticks #17

Closed
maichmueller opened this issue Aug 3, 2020 · 1 comment
Closed

Disabling (or adjusting) border ticks #17

maichmueller opened this issue Aug 3, 2020 · 1 comment

Comments

@maichmueller
Copy link

maichmueller commented Aug 3, 2020

Hey,

first of: thanks for the great styles!
I would however like to disable (or adjust if possible) the ticks the style draws on the borders of a plot. Specifically, when I'm building a subplot figure with a big figure around it to easily have a shared x, and y label, as well as legend, then the border ticks of the invisible frame stay visible.
The following code should showcase the problem:

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

plt.style.use("science")
fig, axes = plt.subplots(5,2, figsize=(8,6), sharex=True, sharey=True)
axes = axes.flatten()
big = fig.add_subplot(111, frameon=False)
plt.tick_params(labelcolor='none', top=False, bottom=False, left=False, right=False)

for ax in axes:
    ax.hist(
        np.random.normal(size=10000) + np.random.randint(0,10),
        density=True,
        bins=200,
    )

plt.show()

Note how the ticks are even plotted between two subplots in the whitespace. If you know how to selectively disable this, it would be appreciated.

Best regards,
Michael

@garrettj403
Copy link
Owner

For your example, you just need to get rid of the ticks by setting: ax.set_xticks([], [])

Here's the correct code:

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

plt.style.use("science")

fig, axes = plt.subplots(5,2, figsize=(8,6), sharex=True, sharey=True)

big = fig.add_subplot(111, frameon=False)
big.set_xticks([], [])
big.set_yticks([], [])

axes = axes.flatten()
for ax in axes:
    ax.hist(
        np.random.normal(size=10000) + np.random.randint(0,10),
        density=True,
        bins=200,
    )

plt.show()

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

2 participants