0

I am trying to plot a curve with my selection of distance between points in X or Y axis. I need to know how can i define the values by myself.

Here are the simple codes I am using for a simple curve

import matplotlib.pyplot as plt
plt.figure(figsize=(10,7)) # 10 is width, 7 is height
plt.plot([1,2,3,4,5], [1,2,3,4,10], 'go', label='GreenDots')
plt.plot([1,2,3,4,5], [2,3,4,5,11], 'b*', label='Bluestars')
plt.title('A Simple Scatterplot')
plt.xlabel('X')
plt.ylabel('Y')
plt.xlim(0, 6)
plt.ylim(0, 12)
plt.legend(loc='best')
plt.show()

Which give me this output figure enter image description here

But I distance value between each point in the Y-axis to be 1 or in X-axis to be 2. Inshort, I want to select my own values.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
dm5
  • 350
  • 1
  • 6
  • 18
  • I don't understand what you want to do. Can you give an explicit example of your desired input and resulting output? Is the plot you give the desired output already? – Energya Sep 23 '19 at 09:20
  • 1
    In the output I gave, you can see Y-axis values has a space of 2 values between each (0,2,4....12) AND X-axis has 1 value between each (1,2,3,.....6). These values are by default. I want to specify my own values, lets say X-axis to be 2,4 and 6 or Y-axis to be 1,2,3... – dm5 Sep 23 '19 at 09:25

1 Answers1

0

What you're describing based on your comment are called the ticks on the axis.

You can set them yourself using the plt.xticks() and plt.yticks() methods.

plt.xticks([0, 2, 4, 6])
plt.yticks(list(range(13)))  # [0, ..., 12]

For a more elaborate answer, see e.g. here

Energya
  • 2,623
  • 2
  • 19
  • 24