[Matplotlib-users] matplotlib interactive in a shell terminal?

Raphael Raccuia rafael.raccuia at blindekinder.com
Mon May 18 18:04:41 EDT 2020


Thank you Matt,

since the visual of my plot is almost finished and nice, I'm not sure 
I'll learn another language at the moment.

Anyway, I fixed my script to work with P2.7, and learned how to use 
Puredata [pyext] object, but now I have the following issue, related to 
the initial one:

plt.ion()
plt.plot([1, 2, 3, 4], [1, 4, 2, 3])
plt.show(block=True)

The plot is interactive, PD sends instructions to Python to fill and 
modify. If */block/* = */True/*, it displays the plot in Tk window, but 
since it's blocked, PD doesn't respond until I close the window.
If /*block*/ = */False/*, Tk window appear, empty, and impossible to 
close, but PD remains functional.

any idea how to fix that?
rph

Le 18.05.20 à 15:59, Matt Newville a écrit :
> Raphael,
>
> Depending on your needs, you might find wxmplot useful.  This supports 
> non-blocking, interactive 2D plots and image display from a terminal 
> Python or IPython session.  As the name might imply, it 
> requires wxPython but is installed with `pip install wxmplot` if your 
> Linux Python has wxPython available (Anaconda Python does).  With this 
> installed, you can do
>
> >>> import numpy as np
> >>> import wxmplot.interactive as wi
> >>> x = np.linspace(0, 20, 101)
> >>> wi.plot(x, np.sin(x), xlabel='t(s)')
> <wxmplot.interactive.PlotDisplay at 0x10db88678>
> >>> wi.plot(x, np.cos(x)*np.exp(-x/10))
> <wxmplot.interactive.PlotDisplay at 0x10db88678>
>
> The first plot() there will show an interactive display of the plot 
> and return the prompt.  The second plot() here add the trace on top of 
> the first (you can add optional arguments to open a second plot window 
> or draw to right-hand axes). The plot windows have drag-and-zoom and 
> many configuration options for colors, themes, etc available after the 
> plot has been displayed.  There is also a 
> `wxmpot.interactive.imshow()` to show an interactive false-color image 
> of 2D data. See 
> https://newville.github.io/wxmplot/interactive.html for more details.
>
> Of course, these do not do everything available in matplotlib, but if 
> you are doing basic 2D line plots or image display they should go a 
> long way.  And you can grab that return value and its 
> `PlotDisplay.panel.axes` (a matplotlib Axes) and 
> `PlotDisplay.panel.fig` (a matplotib Figure) if you want to do more 
> complicated things.
>
> --Matt
>
> On Mon, May 18, 2020 at 3:43 AM Raphael Raccuia 
> <rafael.raccuia at blindekinder.com 
> <mailto:rafael.raccuia at blindekinder.com>> wrote:
>
>     Hi,
>     Any chance  to use matplotlib in a linux shell terminal?
>
>     if I make 'python3 my/script.py', it displays the plot but I have no
>     prompt >>>.
>     It works in Idle.
>     That would be my test script:
>
>     #!/usr/bin/env python3 #otherwise loads a 'ghost': cursor turn to
>     cross,
>     but no window.
>
>     import matplotlib
>     print(matplotlib.get_backend()) #print TkAgg in the terminal
>
>     import matplotlib.pyplot as plt
>
>     plt.ion()
>
>
>     plt.plot([1, 2, 3, 4], [1, 4, 2, 3])
>
>     plt.show(block=True) #block=True: othewise it close immediately
>     plot and
>     terminal
>
>     thank you!
>
>     rph-r
>
>
>     _______________________________________________
>     Matplotlib-users mailing list
>     Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
>     https://mail.python.org/mailman/listinfo/matplotlib-users
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20200519/784f4b3b/attachment.html>


More information about the Matplotlib-users mailing list