0
import matplotlib.pyplot as plt

x_value = range(1, 500)
y_value = [x**3 for x in x_value]


plt.style.use('Solarize_Light2')
fig, ax = plt.subplots()
ax.scatter(x_value, y_value,c = y_value,cmap = plt.cm.Blues, s = 5)

ax.set_title('Square number', fontsize = 24)
ax.set_xlabel('value', fontsize = 14)
ax.set_ylabel('square of the value', fontsize = 14)
ax.tick_params(axis = 'both',which = 'major', labelsize = 14)

ax.axis([0, 540, 0, 125500000])

plt.show()
plt.savefig('otp.jpeg', bbox_inchs = 'tight')

The program runs correctly. it gives a blue color to the line but in the problems tab it shows that Module 'matplotlib.cm' has no 'Blues' member . so what is the possible solution

  • 1
    This wrong problem message probably is due to matplotlib adding some functions in a dynamic way. See e.g. [this pylint issue](https://github.com/PyCQA/pylint/issues/2289). Apart from that, calling `plt.show()` erases the plot, leaving an empty image for `plt.savefig()`. Calling `plt.show()` last would avoid that problem. – JohanC Dec 26 '20 at 18:54
  • I use Eclipse with PyDev. When I call colormaps with `plt.cm.Blues` etc, it always pretends that these colormaps don't exist and gives me a "Undefined variable from import" error message. Knowing that it does not have any influence on the script execution, I simply ignore this problem now. – Mr. T Dec 26 '20 at 21:41
  • yep. ignoring is the only way i guess. and thanks @JohanC for solving another problem of blank saved graph. – Shagoto Roy Dec 31 '20 at 11:01

1 Answers1

0

Try using:

cmap=plt.colormaps.get_cmap("Spectral")
S.B
  • 13,077
  • 10
  • 22
  • 49