Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to plot a graph using 2 lists having a null value in matplotlib?

import matplotlib.pyplot as xy
a= [1,3,5,3,'',4]
b=[1,2,3,4,5,6]
xy.plot(b,a)
xy.show()

This code is throwing an error saying "ValueError: could not convert string to float:"

like image 931
ayush nigam Avatar asked Jul 24 '26 22:07

ayush nigam


1 Answers

Create 2 new lists, that only contain valid data, which is then used for plotting. The example below skips this copying step and assumes that data from a and b can be deleted without causing any issues. If in doubt, just create a copy of both before doing the for-loop.

a=[1,3,5,3,'',4]
b=[1,2,3,4,5,6]

for index in range(len(a)-1):
    if a[index] is '':
        del a[index]
        del b[index]
like image 98
jhoepken Avatar answered Jul 27 '26 11:07

jhoepken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!