Difference in plotting with different matplotlib versions

The data is read in as strings. In matplotlib 2.0 those were automatically converted to floating point numbers such that they can be plotted.

In matplotlib 2.1, categorical plots have been introduced. This now allows for something like

plt.plot(["apple", "banana", "cherry"], [2,1,3])

While this is of course great for certain applications, it breaks the previous option of plotting strings that are convertable to floats. I guess this if fine, it just gives the user the responsibility to do the conversion himself.

In this case you would want to do this conversion like

values = [None if v is '' else float(v) for v in values]

In case you already have a numpy array: np.array(values).astype(float)

In general, one can use numpy.loadtxt to read files into float arrays. If the file contains dates, usage of a converter as in reading a comma-delimited file with a date object and a float with Python would be possible.

Another option to read in text files would be pandas.read_csv.

Leave a Comment