Reputation: 57
I want to do a grid on python. I know it's possible using matplotlib
, but I do struggle.
The grid I want to obtain is like the one on this graph. This means 8 row, and 13 columns.
Upvotes: 2
Views: 969
Reputation: 39042
Without having access to the data to reproduce your figure (without grid), it's impossible to provide a working code to you. However, below is one basic example on how to do it. The trick here is to use major ticks at spacing of 1 ranging from 1 to 13 on the x-axis and ranging from 1 to 8 on y-axis. Then you need to turn on the grid using plt.grid()
and use linestyle='dotted'
to get the grid similar to what you want.
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randint(1, 14, 50)
y = np.random.randint(1, 9, 50)
plt.plot(x, y, 'bo')
plt.xticks(range(1, 14));
plt.yticks(range(1, 9));
plt.grid(linestyle='dotted')
Upvotes: 2