[Matplotlib-users] Possible regression in plotting lists of strings after 2.0
Thomas Caswell
tcaswell at gmail.com
Sat Oct 27 12:59:49 EDT 2018
This is an intentional change to support categorical string-data (see
https://matplotlib.org/gallery/lines_bars_and_markers/categorical_variables.html)
in 2.1.
Plotting a list of strings that happened to be floats worked <2.1 by chance
because there was a `np.asarray(data)` someplace which worked because numpy
implicitly did the conversion. You are not the only person to hit this,
we miss-estimated how used this accidental feature was, sorry.
The most reliable path is to convert your data to numeric types before
handing it to Matplotlib (this will be guaranteed to work on all past and
future versions of Matplotlib!).
Tom
On Thu, Oct 25, 2018 at 1:08 AM Douglas Clowes <douglas.clowes at gmail.com>
wrote:
>
>
> On Thu, Oct 25, 2018 at 2:19 PM Douglas Clowes <douglas.clowes at gmail.com>
> wrote:
>
>> I had a program that seemed to work fine on Fedora 27 (matplotlib 2.0.0)
>> but exhibits strange behaviour on Fedora 29 (matplotlib 2.2.3) and Rawhide
>> (matplotlib 3.0.0). Behaviour is the same with either python 2 or 3.
>>
>> The following "minimalist" program performs well where "y" is a list of
>> floats and on 2.0.0 with either floats or strings. On later versions with
>> strings:
>> * it plots a straight line
>> * has y-axis labels on every point
>> * has linear spacing of non-linear points on y-axis
>> * pressing "l" (lower-case L) yields a different scale and labels
>>
>> With read data (not monotonic) it yields even stranger results.
>>
>> Since it used to work, is it expected to work with strings or did I just
>> get lucky?
>>
>> #!/usr/bin/env python3
>> import csv
>> import sys
>> import matplotlib.pyplot as plt
>>
>> x = range(11)
>> if "-s" in sys.argv:
>> y = [str(i*i) for i in x]
>> print("Strings")
>> else:
>> y = [i*i for i in x]
>> print("Floats")
>> plt.subplot(111)
>> plt.grid(True)
>> print("preplot")
>> plt.plot(x, y, "+-")
>> print("pretight")
>> plt.tight_layout()
>> print("presave")
>> plt.savefig("plot.svg")
>> print("preshow")
>> plt.show()
>>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20181027/f9240382/attachment.html>
More information about the Matplotlib-users
mailing list