How to display the value of a variable in the title of a plot?

4,808 views
Skip to first unread message

chobb...@gmail.com

unread,
May 6, 2016, 11:19:46 AM5/6/16
to julia-users
I tried my best to search answers to my following quick questions in this group and PyPlot's site, though I trust that my questions are just very basic ones:

1. How to display the value of a variable in the title of a plot? In matlab, I do the following to show the value of pi in the title:

title(['\pi = ' num2str(pi)])

Can anyone teach me on how to do this in PyPlot?

2. Is there a counterpart of the `shg` command in PyPlot to pop the recent figures to the front?

Thanks!!




Tom Breloff

unread,
May 6, 2016, 11:38:20 AM5/6/16
to julia-users
Just use string interpolation (this is a Julia thing, not specific to PyPlot).

title("\pi = $pi")

Steven G. Johnson

unread,
May 6, 2016, 11:50:12 AM5/6/16
to julia-users


On Friday, May 6, 2016 at 11:38:20 AM UTC-4, Tom Breloff wrote:
Just use string interpolation (this is a Julia thing, not specific to PyPlot).

title("\pi = $pi")

To get Matplotlib to use LaTeX for π, you need (escaped) dollar signs and also to escape the backslash: title("\$\\pi\$ = $pi").  Or you can use Unicode for \pi: title("π = $pi").

Note that string(pi) is "π = 3.1415926535897...", however, so for this particular example you probably want
    title("π ≈ $(Float64(pi))")

chobb...@gmail.com

unread,
May 6, 2016, 12:55:45 PM5/6/16
to julia-users
Tom and Steven,

Thanks the hints!!

Still, how could I show all current figures by command? That is something like 'shg' in Matlab.

Also, is there a command to close all current figures, i.e. a counterpart of 'clf' in Matlab?

Thanks!

Steven G. Johnson

unread,
May 6, 2016, 1:17:12 PM5/6/16
to julia-users


On Friday, May 6, 2016 at 12:55:45 PM UTC-4, chobb...@gmail.com wrote:
Tom and Steven,

Thanks the hints!!

Still, how could I show all current figures by command? That is something like 'shg' in Matlab.

I don't think Matplotlib supports this; the only things I could find were specific to the Qt backend:

 
Also, is there a command to close all current figures, i.e. a counterpart of 'clf' in Matlab?

close("all") in PyPlot (from the Matplotlib docs). 

In general, if you are using PyPlot and want to know how to do something, just google the matplotlib documentation, and then translate the syntax back to Julia.

chobb...@gmail.com

unread,
May 9, 2016, 8:44:30 AM5/9/16
to julia-users
Steven - Sorry. I just saw your last reply.

Thanks for the hints. `close("all")` works absolutely superbly. But Qt backend is far beyond my universe.

Thanks again!
Reply all
Reply to author
Forward
0 new messages