简体   繁体   中英

Matplotlib line won't show up

I'm trying to make a very simple graph in matplotlib, and for some reason it produces a graph without a line.

The plotting code:

    print(infected_list)
    print(generations_list)
    plt.plot([generations_list],[infected_list])
    plt.ylabel("Infected")
    plt.xlabel("Generations")
    plt.show()

I've also tried it with:

plt.plot([generations_list],[infected_list],color="red")

The output of the print function, showing the values of infected_list and generations_list:

[1, 2, 3.6, 6.8, 13.2, 26.0, 51.6, 100, 100, 100, 100, 100]
[0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

The resulting graph, with no line: 无线图

Any ideas what I'm doing wrong? Thank you!

It was a very simple mistake on my part, I was passing a list of a list. All I had to do was change

plt.plot([generations_list],[infected_list])

to

plt.plot(generations_list,infected_list)

Thank you to Mateen Ulhaq for answering it so quickly!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM