How do you draw R-style axis ticks that point outward from the axes in Matplotlib?


To draw R-style (default is regular style) axis ticks that point outward from the axes in matplotlib, we can use rcParams["xticks.direction"]="out" for X-axis.

Steps

  • Set the figure size and adjust the padding between and around the subplots.

  • Set outwaord tick points using plt.rcParams.

  • Initialize a variable for the number of data points.

  • Create x and y data points using numpy.

  • Plot x and y data points using plot() method.

  • To display the figure, use show() method.

Example

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.rcParams['ytick.direction'] = 'out' # in
plt.rcParams['xtick.direction'] = 'out' # in
n = 10
x = np.linspace(-2, 2, n)
y = np.exp(x)
plt.plot(x, y)
plt.show()

Output


Updated on: 01-Jun-2021

150 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements