0

I'm new to matplotlib and pandas and have been wondering how to change the intervals of my plots. I have a .csv file(data file)(link to the csv file) and plotted a graph in this form my graph

below is the code I used to achieve this:

import matplotlib.pyplot as plt
import csv
import numpy as np
import pandas as pd
from matplotlib import style

data = pd.read_csv('data.csv')
print(data)

x = range(len(data.occurrence))
plt.figure(figsize=(8,5))
plt.title('Number of Occurrence with five samples', fontdict={'fontweight':'bold', 'fontsize':10})
plt.xlabel('Occurrence', fontdict={'fontweight':'bold', 'fontsize':10})
plt.ylabel('Samples', fontdict={'fontweight':'bold', 'fontsize':10})
plt.plot(x, data.one, label='R 15')
plt.plot(x, data.two, label='R 12')
plt.plot(x, data.three, label='R 9')
plt.plot(x, data.four, label='R 6')
plt.plot(x, data.five, label='R 3')

plt.legend(fontsize=5)
plt.show()

I would appreciate if someone could show me how to change the interval of my X-axis from 5 to 2 (i.e. 0,2,4,6,8,10,...,30). Thanks!

BaoLuo
  • 13
  • 3
  • Yes, it does. Thanks @Mr.T. Placing `plt.xticks(np.arange(min(x), max(x)+1, 2.0))` in between the code gives me the 2.0 interval I needed for the x-axis. – BaoLuo Feb 07 '22 at 08:39

0 Answers0