Python Forum
Using matplotlib in Spyder v/s REPL
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using matplotlib in Spyder v/s REPL
#1
Hi, I am just starting off with Python and was playing around with matplotlib package.
I wrote a few lines as below to plot a graph
def plotgrh():
  import matplotlib.pyplot as plt
 
  fig, ax = plt.subplots(1,2)
  print("I am plotting graph")
  plt.plot([6,1,8,4],[4,7,2,1])
  print("Graph plotted")
I am able to import the above module and run plotgrh() in Spyder. I can see the graph plotted in the "Plots" tab in Spyder console.The msgs I am printing also get displayed. But if I open a powershell prompt, start python and run plotgrh() in the Python prompt (>>>), then only the print msgs are displayed but the graph is not displayed. What is need to get the graph plotted? Should I include any additional modules? The reason I need this is, I am trying to create some scripts that will plot graphs and want to be able to run them as a Windows application or from a DOS command prompt and not from within Spyder. Any suggestions/pointers is highly appreciated.
Reply
#2
You could try plt.show(block=False) perhaps.
Reply
#3
If this running outside a environment like Sypder/REPL/Notebook.
The need to use plt.show() to show the plot.
import matplotlib.pyplot as plt

def plotgrh():
    fig, ax = plt.subplots(1,2)
    print("I am plotting graph")
    plt.plot([6,1,8,4],[4,7,2,1])
    # Uncomment for save plot
    #plt.savefig('Graph.png')
    plt.show()
    print("Graph plotted")

plotgrh()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  help for use print in REPL jip31 10 4,123 Apr-30-2021, 03:52 PM
Last Post: bowlofred
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,161 Mar-11-2021, 10:52 AM
Last Post: buran
  Using my REPL to bisect numbers and lists with classes (PyBite #181) Drone4four 2 2,005 Sep-24-2020, 01:47 PM
Last Post: Drone4four
  Online python repl? Gribouillis 4 33,062 Apr-09-2020, 12:19 PM
Last Post: Gribouillis
  REPL grkiran2011 1 2,074 Jan-08-2020, 11:47 PM
Last Post: Gribouillis
  Embedding or adding IDE like "repl" inside Flask app sray 1 2,191 Jul-03-2019, 03:13 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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