For some set of data, here is my code
JavaScript
x
10
10
1
import matplotlib.pyplot as plt
2
year = []
3
relative_recurrence = []
4
f = open('relative recurrence plot.txt', 'r')
5
for row in f:
6
row = row.split(' ')
7
year.append(row[0])
8
relative_recurrence.append(float(row[1]))
9
plt.bar(year, relative_recurrence, color = 'g', label = 'HILDCAAS')
10
which generates a bar graph like this:
The values on the x-axis ranges from 1975 to 2017. And the values on the y-axis are some decimal values. In the x-axis of the plot, the values are overlapping. I want to change the scale as 1975, 1980, 1985 so on to keep them distinct and visible.
What is the required command?
I tried the xlim() command. But it didn’t work.
Advertisement
Answer
Try this:
JavaScript
1
11
11
1
import matplotlib.pyplot as plt
2
year = []
3
relative_recurrence = []
4
f = open('relative recurrence plot.txt','r')
5
for row in f:
6
row = row.split(' ')
7
year.append(float(row[0]))
8
relative_recurrence.append(float(row[1]))
9
plt.bar(year, relative_recurrence,color = 'g', label = 'HILDCAAS')
10
plt.xticks(np.arange(min(year), max(year) + 1, 5.0))
11