1

Simple problem: With matplotlib, I want to have this style preset:

Bottom and left ticks: direction out, label on
top and right ticks: direction in, label off

I want to have this style as a preset, so I dont have to do it for every single plot. The following code gives me the top and right ticks, but I cant manage to change their direction.

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["xtick.top"] = True 
plt.rcParams["ytick.right"] = True

somearray=np.arange(0.0, 1.0, 0.1)

plt.figure()
plt.plot(somearray[:], somearray[:])
plt.xlabel('x')
plt.ylabel('y')
plt.show()
  • If you were setting them at runtime how would you do it? Which tick parameters would you change and to what? Are any of the parameters listed in [this Matplotlib rcParams tutorial](https://matplotlib.org/3.3.2/tutorials/introductory/customizing.html#a-sample-matplotlibrc-file) what you need? – wwii Oct 10 '20 at 18:38
  • 1
    Do you have twin Axes? - multiple scales? Your [mre] should probably include a minimal example of your figure and the code to produce it. – wwii Oct 10 '20 at 18:52
  • 1
    Does this answewr your question? [In matplotlib, how do you draw R-style axis ticks that point outward from the axes?](https://stackoverflow.com/questions/6260055/in-matplotlib-how-do-you-draw-r-style-axis-ticks-that-point-outward-from-the-ax); or [How to set default tick params in python/matplotlib?](https://stackoverflow.com/questions/57719124/how-to-set-default-tick-params-in-python-matplotlib). – wwii Oct 10 '20 at 20:53

1 Answers1

1

You can use x(y)ticks.direction to set the ticks inside. It's simple to update the parameters in the form of a dictionary.

import numpy as np
import matplotlib.pyplot as plt

# plt.rcParams["xtick.top"] = True 
# plt.rcParams["ytick.right"] = True
# plt.rcParams['xtick.direction'] = 'in'
# plt.rcParams['ytick.direction'] = 'in'

params = {"xtick.top": True, "ytick.right": True, "xtick.direction": "in", "ytick.direction": "in"}
plt.rcParams.update(params)

somearray = np.arange(0.0, 1.0, 0.1)

plt.figure()
plt.plot(somearray[:], somearray[:])
plt.xlabel('x')
plt.ylabel('y')
plt.show()
wwii
  • 23,232
  • 7
  • 37
  • 77
r-beginners
  • 31,170
  • 3
  • 14
  • 32