3
當我使用Python2,我可以繪製圖表使用pylab.scatter和CMAP在Python 3.5.1
from sklearn import datasets
from matplotlib.colors import ListedColormap
circles = datasets.make_circles()
colors = ListedColormap(['red', 'blue'])
pyplot.figure(figsize(8, 8))
pyplot.scatter(map(lambda x: x[0], circles[0]), map(lambda x: x[1], circles[0]), c = circles[1], cmap = colors)
但是當我使用Python3,我不能這樣做。我試圖改變顏色,但不能。
我收到許多錯誤:
ValueError: length of rgba sequence should be either 3 or 4
During handling of the above exception, another exception occurred:
ValueError: to_rgba: Invalid rgba arg "[0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 0 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 0 0 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 0 1 1 0 0 0 0 1]"
length of rgba sequence should be either 3 or 4
During handling of the above exception, another exception occurred:
ValueError: Color array must be two-dimensional
我該如何解決這個問題?
什麼的'版本matplotlib'你使用Py2和Py3? – MattDMo
好吧,如果它讓你感覺更好,我會在Linux上獲得與matplotlib 1.5.1和Python 2.7.11和3.5.1相同的結果。奇怪... – MattDMo
1)Anaconda + Python 2.7.1 + Matplotlib 1.5.1 - 一切正常 2)Anaconda + Python 3.5.1 + Matplotlib 1.5.1 - 全部不好 –