<jupyter_start><jupyter_text>Major and Minor Ticks<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
ax = plt.axes(xscale='log', yscale='log')
print(ax.xaxis.get_major_locator())
print(ax.xaxis.get_minor_locator())
print(ax.xaxis.get_major_formatter())
print(ax.xaxis.get_minor_formatter())<jupyter_output><matplotlib.ticker.LogFormatterSciNotation object at 0x000001726856F2E8>
<matplotlib.ticker.LogFormatterSciNotation object at 0x000001726A3CC2E8><jupyter_text>Hiding Ticks or Labels<jupyter_code>ax = plt.axes()
ax.plot(np.random.rand(50))

ax.yaxis.set_major_locator(plt.NullLocator())
ax.xaxis.set_major_formatter(plt.NullFormatter())
fig, ax = plt.subplots(5,5, figsize=(5,5))
from sklearn.datasets import fetch_olivetti_faces
faces = fetch_olivetti_faces().images
for i in range(5):
    for j in range(5):
        ax[i, j].xaxis.set_major_locator(plt.NullLocator())
        ax[i, j].yaxis.set_major_locator(plt.NullLocator())
        ax[i, j].imshow(faces[10 * i + j], cmap="bone")<jupyter_output><empty_output><jupyter_text>Reducing or Increasing the Number of Ticks<jupyter_code>fig, ax = plt.subplots(4,4, sharex=True, sharey=True)
for axi in ax.flat:
    axi.xaxis.set_major_locator(plt.MaxNLocator(3))
    axi.yaxis.set_major_locator(plt.MaxNLocator(3))
fig<jupyter_output><empty_output><jupyter_text>__Makes things cleaner__  Fancy Tick Formats<jupyter_code>fig, ax = plt.subplots()
x = np.linspace(0, 3*np.pi, 1000)
ax.plot(x, np.sin(x), lw=3, label='sine')
ax.plot(x, np.cos(x), lw=3, label='cosine')

# set up the grid, legend, and limits
ax.grid(True)
ax.legend(frameon=False)
ax.axis('equal')
ax.set_xlim(0, 3*np.pi)
ax.xaxis.set_major_locator(plt.MultipleLocator(np.pi/2))
ax.xaxis.set_minor_locator(plt.MultipleLocator(np.pi/4))
fig<jupyter_output><empty_output><jupyter_text>for more fine-grained stuff, we may have to create a custom function and using `plt.FuncFormatter()`<jupyter_code>def format_func(value, tick_number):
    # find number of multipes of pi/2
    N = int(np.round(value/(np.pi/2)))
    if N == 0:
        return "0"
    elif N == 1:
        return r"$\pi/2$"
    elif N == 2:
        return r"$\pi$"
    elif N % 2 > 0:
        return r"${0}\pi/2$".format(N)
    else:
        return r"${0}\pi$".format(N//2)
    
ax.xaxis.set_major_formatter(plt.FuncFormatter(format_func))
fig<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1475206611570248, 'fraction_numerical': 0.02768595041322314, 'mean_word_length': 5.387862796833773, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '655278', 'license': 'MIT', 'n_tokens_mistral': 1031, 'n_tokens_neox': 978, 'n_words': 163, 'path': 'Chapter4/Customizing Ticks.ipynb', 'repo_name': 'Aroogz/Python-Data-Science-Handbook-Notes', 'size': '2420'}