Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Chart visualization, one year with multiple visualization points

I am trying to code a very simple visualization – election_year and number of votes on a chart.
However, last 3 times the elections were held the same year – in April, July and November of 2021, which the charts reads as one event. How can I break the year into parts to create several chart points?
Here’s the code:

import matplotlib.pyplot as plt
election_year = [2009, 2013, 2014, 2017, 2021, 2021, 2021]
voters = [1678641, 1081605, 1072491, 1147283, 837671, 642165, 596456]
plt.plot(election_year, voters)
plt.show()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You say one thing, but your code says another.
You’re telling that three elections were held in the same year, so if you only care about the year, you should sum the voters for 2021 and have one 2021 in election_year with the accumulated votes.

But if you want these three different elections held in 2021 to be, in fact, separated, why do you give all three the same key (2021)? You can separate them by something like this.

import matplotlib.pyplot as plt
election_year = [2009, 2013, 2014, 2017, "2021 - a", "2021 - b", "2021 - c"]
voters = [1678641, 1081605, 1072491, 1147283, 837671, 642165, 596456]
plt.plot(election_year, voters)
plt.show()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading