0
import matplotlib.pyplot as plt
import numpy as np

delta = 0.0001

t = np.arange(0,5+delta,delta)

xt = np.sin(np.pi*t)

fig = plt.figure(1)

ax1= plt.subplot(3,2,1)
ax1.plot(t,xt, "tab:red")
ax1.set(ylabel = "Amplitude")
ax1.set(xlabel = 'Time(s)')
ax1.set(title = 'for n = 1')
ax1.grid()

ax2 = plt.subplot(3,2,2)
ax2.plot(t,xt, "tab:green")
ax2.set(ylabel = "Amplitude")
ax2.set(xlabel = 'Time(s)')
ax2.set(title = 'for n = 2')
ax2.grid()


plt.tight_layout()


plt.show()

Hi this is just a snip of my code but my problem basically is with the x axis of the subplots. On the axis the values jump from 0-2-4 and I need it to be from 0-1-2-3-4-5. Is there a way I can get those values to display on the x axis rather than just 0-2-4.

MolliMm
  • 3
  • 1

2 Answers2

0

you can set the locator for x axis.

import matplotlib as mpl
ax1.xaxis.set_major_locator(mpl.ticker.MultipleLocator(1))
ax2.xaxis.set_major_locator(mpl.ticker.MultipleLocator(1))
Chang Ye
  • 1,105
  • 1
  • 12
  • 25
0

There are several possible ways of doing this. One of the simplest is to manually set the x ticks.

ax1.set_xticks(np.arange(6))
ax2.set_xticks(np.arange(6))
jmd_dk
  • 12,125
  • 9
  • 63
  • 94