1

I am trying to create a simple graph using below code.

Y = [DUPLICATE_INCIDENT_5, DUPLICATE_INCIDENT_4, DUPLICATE_INCIDENT_3, DUPLICATE_INCIDENT_2, DUPLICATE_INCIDENT]
X = ['9th', '10th', '11th', '12th', '13th']
plt.plot(X, Y, marker='o', linestyle='--', color='g')
plt.ylabel('DUPLICATE INCIDENTS')
plt.xlabel('July')
plt.show()
plt.savefig('duplicates.svg')

enter image description here

This just created an x-axis with the date values and y-axis with count of incidents. I want to display the graph in an order i.e. Starting from 0 - N as reference values on Y axis and plot the COUNT 8..7..13..3..0 against that.

I know this is a stupid question but I am new to matplotlib and am going to start a course on it. Just going though the official documentation to have some basic knowledge before the course starts.

EDIT 1:

DUPLICATE_INCIDENT* - these are all numbers whose values are as printed in the Y axis. [8, 7, 13, 3, 0].

EDIT 2:

My bad - I should have checked ALL the variables defined above before posting a question. One of the above variables was a string. That was causing the issue. It is working as expected now.

Koshur
  • 378
  • 1
  • 6
  • 20
  • what are these `Y = [DUPLICATE_INCIDENT_5, DUPLICATE_INCIDENT_4, DUPLICATE_INCIDENT_3, DUPLICATE_INCIDENT_2, DUPLICATE_INCIDENT]`? – nahusznaj Jul 13 '18 at 12:41
  • 2
    I am not sure what you are trying to achieve. First, we don't know what `DUPLICATE_INCIDENT_5` etc. are. Maybe numbers, maybe strings. Then you plot with strings like "9th" categorical variables. matplotlib doesn't know that you think of numbers, it could be "A", "cat", or "ju&!zyO" for matplotlib. You have to define your data types before you hand it to matplotlib. – Mr. T Jul 13 '18 at 12:42
  • having a look this question https://stackoverflow.com/questions/47373762/pyplot-sorting-y-values-automatically may help you – nahusznaj Jul 13 '18 at 12:44
  • DUPLICATE_INCIDENT* - these are all numbers whose values are as printed in the Y axis. 8,7,13,3,0 – Koshur Jul 13 '18 at 13:18
  • @Mr.T print(Y[0]) returns 8 and print(type(Y[0])) returns . – Koshur Jul 13 '18 at 14:04
  • I'm unable to understand anything from the duplicate link. Can you explain? – Koshur Jul 13 '18 at 14:49
  • It's version 2.2.2 – Koshur Jul 13 '18 at 16:17
  • If you have 2.2, then the linked answer is not the solution to your problems. I vote to reopen the question. I cannot reproduce your problem here with `Y = [8, 7, 13, 3, 0]`, though. And please edit your question and include the added information. – Mr. T Jul 13 '18 at 16:46
  • It was my silly mistake. I should have checked all the variables before posting a question One of the DUPLICATE_INCIDENT* variables was a string. That was causing the above issue. It is working as expected now.. – Koshur Jul 13 '18 at 17:49
  • In this case, it would have been closed because the error is not reproducible. I would have retracted my reopen vote but it is not possible. – Mr. T Jul 14 '18 at 07:04

0 Answers0