close

How to plot a chart in the terminal?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to plot a chart in the terminal in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to plot a chart in the terminal?

  1. How to plot a chart in the terminal?

    If you call plot() several times prior to this call, it will then pop an equal amount of windows with the respective charts. Control returns to Python only when you close all popped chart windows.

  2. plot a chart in the terminal

    If you call plot() several times prior to this call, it will then pop an equal amount of windows with the respective charts. Control returns to Python only when you close all popped chart windows.

Method 1

You have a couple of options here:

  1. Export to image or PDF. Information found here: http://matplotlib.org/faq/howto_faq.html The key piece of information here is below:# do this before importing pylab or pyplot import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.plot([1,2,3]) fig.savefig('test.png')
  2. If your server supports X11 forwarding (or if you can enable/install X11 forwarding), you can SSH into the server by setting your display. From linux, run:DISPLAY=:0.0 ssh -Y <server ip> This will set up your machine to forward any display output from the server to your PC. If you are running Windows, you can use MobaXterm which makes it easy, or configure an X11 client yourself. Mac is similarly easy if I remember correctly.

Method 2


If you want to pop an external window with the chart, run the plot and then

>>> matplotlib.pyplot.show(block=True)

This will pop the chart in a separate window.

If you call plot() several times prior to this call, it will then pop an equal amount of windows with the respective charts. Control returns to Python only when you close all popped chart windows.

I like to wrap it in a little helper function, like so:

def show():
   return matplotlib.pyplot.show(block=True) 

Then I just call show() whenever I want to see any yet unshown plots.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read