Re: Possible regression in plotting lists of strings after 2.0

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Possible regression in plotting lists of strings after 2.0

Douglas Clowes


On Thu, Oct 25, 2018 at 2:19 PM Douglas Clowes <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Possible regression in plotting lists of strings after 2.0

tcaswell
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 <[hidden email]> wrote:


On Thu, Oct 25, 2018 at 2:19 PM Douglas Clowes <[hidden email]> 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
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users