0

I am trying to make a graph with fixed ticks, regardless to the points values. For example, I want the ticks to be 0-6, and the points values to be 0, 1, 3. I'd use this code:

import matplotlib.pyplot as plt
import numpy as np

x_points = np.array([0, 1, 3])
y_points = np.array([0, 1, 3])
x_ticks = np.arange(0, 7, 1)
y_ticks = np.arange(0, 7, 1)

plt.xticks(x_ticks)
plt.yticks(y_ticks)
plt.plot(x_points, y_points)
plt.show()

But the result is only 0, 1, 3 ticks - which are the ticks for the actual current values, and not the values I set using xticks and yticks:

Current graph

And I would like to have the ticks fixed, regardless to whether the points values are actually represented in the graph or not, something like that:

Example of target graph

How can I make the axis' ticks to be fixed, regardless of the values it has?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Ron
  • 1
  • 1
  • can you provide some of the actual data? I really do not understand what you want – goku May 06 '22 at 20:59
  • @goku I changed the main post and added an example of how I want it to be. (not the best sketch, but should do the work). I hope it is better now. Is there any more information you would like to know? – Ron May 06 '22 at 21:13
  • use `plt.ylim(0, 6)` – Ali_Sh May 06 '22 at 21:15

1 Answers1

0

Try this:

import matplotlib.pyplot as plt
import numpy as np


x_ticks = np.arange(0, 7, 1)
y_ticks = np.arange(0, 7, 1)

plt.xticks(x_ticks)
plt.yticks(y_ticks)
plt.plot(range(0, 7))
plt.show()

Then add your points to the figure

goku
  • 167
  • 10