Logarithmic Ticks on Top and Right Spine

Question:

I am trying to make a visualization with logarithmic ticks on all sides of the box.

import numpy as np
import matplotlib.pyplot as plt

x  = np.logspace(2, 5, 5)
y  = 0.5*x**(-1/2)
y2 = 0.01*x**(-1/2)
y3 = 0.05*x**(-1/3)

fig, ax = plt.subplots()

ax.plot(x, y, 'o-', label="One")
ax.plot(x, y2, '*-', label="Two")
ax.plot(x, y3, '--', label="Three")

ax.set(
    
    xlabel='Input',
    xlim=(1e2, 1e5),
    xscale='log',
    
    ylabel='Output',
    ylim=(1e-5, 1e-1), 
    yscale='log',   
)

ax.tick_params(top=True, right=True) # <-- This didn't work how I expected.

ax.legend(loc='lower left');

loglogfigure

I would like the associated minor tick marks on the top and right spine.

Any advice on how to make that happen?

Asked By: eitanlees

||

Answers:

Use the which parameter of Axes.tick_params:

ax.tick_params(which='both', top=True, right=True)

Output:

enter image description here

Answered By: BigBen
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.