我设置了颜色'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')
发布于 2020-06-03 20:49:21
原因是cm
是matplotlib
的一部分,而您只导入了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)
https://stackoverflow.com/questions/56416144
复制相似问题