matplotlib模块没有“ Blues”成员

时间:2019-06-02 14:54:17

标签: python-3.x

我将颜色设置为'Blues',它可以成功运行并显示无花果,但输出结果在这里显示了一个问题“ cmap = plt.cm.Blues”,并且无法保存无花果

import matplotlib.pyplot as plt


x_values = list(range(1,1001))
y_values = [x**2 for x in x_values]


plt.scatter(x_values, y_values, c= y_values, cmap=plt.cm.Blues, edgecolor= 'none',  s=20)

#Set chart title and label axes
plt.title("Square Number" , fontsize= 15)
plt.xlabel("Value", fontsize = 15)
plt.ylabel("Square of Value", fontsize = 10)

#set the range for each axis
plt.axis([0, 1100, 0, 1100000])

#set size of tick labels
plt.tick_params(axis= 'both', which = 'major', labelsize = 8)

plt.show()
plt.savefig('squares_plot.png', bbox_inches= 'tight')

1 个答案:

答案 0 :(得分:1)

原因是cmmatplotlib的一部分,而您仅导入了matplotlib.pyplot

试试这个:

import matplotlib as mpl
# ... your code goes here
plt.scatter(x_values, y_values, c= y_values, cmap=mpl.cm.Blues, edgecolor= 'none',  s=20)