2

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.

enter image description here

2
  • There's far more going on in that image than simply plotting a grid. This is too broad; you haven't given the necessary data, code or context to produce that figure. Commented Dec 26, 2018 at 19:54
  • I know that, I just wanted the grid for the moment. I'll try to do what's left on my own. :) Commented Dec 26, 2018 at 20:24

1 Answer 1

3

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')

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry I'm new, I don't find the button to accept :/
You can click the grey check mark next to my answer
add + 0.5 to the x and y arrays to get the markers in the middle of the grid cells

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.