0

I have these three lists:

amountOfYes = [38, 33, 30, 29, 29, 29, 28, 28, 27, 27, 27, 26, 26, 26, 26]
amountOfNo = [39, 35, 33, 32, 30, 28, 24, 22, 21, 21, 21, 20, 20, 20, 19]
index = [0, 118, 393, 317, 1, 8, 9, 29, 226, 297, 331, 52, 105, 251, 316]

amountOfYes & amountOfNo are lists filled with the amount of Yes and No that the top 15 sessions with most attendance had and Index is a list filled with the correspondent position that voting.

the first voting had 38 yes and 39 no, the 118th had 33 yes and 35 no.

How do I plot the amount of yes and no with the corresponding index?

EDIT:

The idea is to create a line graph similar to this one: Graph with the first 20 votings

This chart has the first 20 votings, I need the votings specific votings of Index

I was going with

plt.plot(amountOfYes[index], label = 'Yes', color = 'red')
plt.plot( amountOfNo[index], label = 'No', color = 'black')

The X-axis should be the index and the Y the number of votes each option got

5
  • 2
    are you trying to make a scatter plot? it's really not clear what you mean - "plot" is not super specific. check out the guide to How to Ask take a step back to think about how your question reads for someone who's not in your head :) I'd start by looking at the matplotlib gallery, decide what it is you want to do specifically, make an earnest attempt to implement it, and then let us know exactly why the result that you get isn't what you're hoping to achieve, and how you're stuck. good luck! Commented Jul 4, 2022 at 22:40
  • 1
    Hey, you have massive gaps in your indices, if the indices ranged from 1 to 15 for example, this would yield a nice plot, but you have them in a range of 300, so you won't get any useful insights from the plot. Commented Jul 4, 2022 at 22:47
  • @Leander the thing is I need to compare the options on specific voting days, not just the first 15 or so Commented Jul 4, 2022 at 22:53
  • @MichaelDelgado, sorry for my poor question, is updated now Commented Jul 4, 2022 at 22:54
  • there's a big difference between positional array indices and the x axis value or independent variable. do you mean you want to plot a line between all the [(x0, yes0) (x1, yes1), ...] values and similarly for no? and if so, why does index go up and down so much? is this value supposed to be the day of year, but you are actually hoping to plot the value "1" as e.g. "366"? or do you want the lines to go back and forth all over the place? it would be really helpful if you could describe what you want to happen in a way that fits the values in your data - index does not range from 0 to 19. Commented Jul 4, 2022 at 23:02

1 Answer 1

1

I don't know if this is what you're going for, but it seems like the most useful way to implement what you want. The gaps in you indices make it hard to get a useful graph. I made strings out of the indices, this way they show up with tick marks of that index.

import matplotlib.pyplot as plt

amountOfYes = [38, 33, 30, 29, 29, 29, 28, 28, 27, 27, 27, 26, 26, 26, 26]
amountOfNo = [39, 35, 33, 32, 30, 28, 24, 22, 21, 21, 21, 20, 20, 20, 19]
index = [0, 118, 393, 317, 1, 8, 9, 29, 226, 297, 331, 52, 105, 251, 316]
index = [str(x) for x in index]
plt.plot(index,amountOfYes, label = 'Yes', color = 'red')
plt.plot(index,amountOfNo, label = 'No', color = 'black')
plt.legend()
plt.xlabel("index")
plt.ylabel("amount of votes")
plt.show()

This results in the following image:

enter image description here

If you do just want the plot with the gaps, I suggest sorting the two vote arrays based on the index array, and plotting index vs amountOfYes and amountOfNo:

import matplotlib.pyplot as plt

amountOfYes = [38, 33, 30, 29, 29, 29, 28, 28, 27, 27, 27, 26, 26, 26, 26]
amountOfNo = [39, 35, 33, 32, 30, 28, 24, 22, 21, 21, 21, 20, 20, 20, 19]
index = [0, 118, 393, 317, 1, 8, 9, 29, 226, 297, 331, 52, 105, 251, 316]

zipped = list(zip(amountOfYes,amountOfNo,index))
zipped.sort(key=lambda x:x[2])

amountOfYes = [x[0] for x in zipped]
amountOfNo = [x[1] for x in zipped]
index = [x[2] for x in zipped]

plt.plot(index,amountOfYes, label = 'Yes', color = 'red')
plt.plot(index,amountOfNo, label = 'No', color = 'black')
plt.legend()
plt.xlabel("index")
plt.ylabel("amount of votes")
plt.show()

which gives the following (note how long the line segments are, a line plot is not really the best way in this case I think, I'd go with a bar plot perhaps, as this suggests some kind of continuity in the gaps): enter image description here

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

3 Comments

just out of curiosity, which option did you prefer?
Oh I just realized you could combine the two, so first sort, then convert to strings, to get the time features without the gaps
Sorry for the late response, I ended up using the second one

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.