Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matplotlib in spyder
#1
Hi everyone,

When I type the below code I get the following output but no graph visual. How do I display graphs with matplotlib when using spyder?

import matplotlib.pyplot as plt
import numpy as np
data = np.arange(10)
data
plt.plot(data)
<IPython.core.display.Javascript object>
<IPython.core.display.HTML object>
Out[3]: [<matplotlib.lines.Line2D at 0x2610f7bc198>]
Reply
#2
for interactive:
import matplotlib.pyplot as plt
import numpy as np
data = np.arange(10)
data
plt.plot(data)
plt.show()
Reply
#3
It still does not work.

Sorry I forgot to add one line of code.

import numpy as np
data = np.arange(10)
data
plt.plot(data)
fig = plt.figure()
I tried adding plt.show()

[python]
import matplotlib.pyplot as plt
import numpy as np
data = np.arange(10)
data
plt.plot(data)
fig = plt.figure()
plt.show()
[\python]
Reply
#4
You didn't import matplotlib.pyplot

Works fine for me
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> data = np.arange(10)
>>> data
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> plt.plot(data)
[<matplotlib.lines.Line2D object at 0x000000000A894F60>]
>>> fig = plt.figure()
>>> plt.show()
Results in image:
   
Reply
#5
It worked now, thanks.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020