Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plots not appearing #1359

Closed
rudrasohan opened this issue Jan 17, 2018 · 13 comments
Closed

Plots not appearing #1359

rudrasohan opened this issue Jan 17, 2018 · 13 comments

Comments

@rudrasohan
Copy link

rudrasohan commented Jan 17, 2018

When I am trying to execute the following code t2.jl
using Plots
f(x) = exp(-x^2/2)
plot(f, -3, 3)
by typing
julia t2.jl in the terminal, nothing is visualised.

But the same thing through Julia command line(or an IJulia notebook)
julia> using Plots
julia> f(x) = exp(-x^2/2)
f (generic function with 1 method)
julia> plot(f, -3, 3)

The plot visualises fine in both of the cases.

Can anyone help regarding this?

I am using julia 0.6.0

@daschw
Copy link
Member

daschw commented Jan 17, 2018

A plot is automatically displayed when it's returned. Otherwise, e.g. in your example in a file, you can use display (display(plot(f, -3, 3)) ) to show the plot.

@daschw daschw closed this as completed Jan 17, 2018
@ParfaitG
Copy link

ParfaitG commented Mar 24, 2019

@daschw, I am facing same exact issue as OP and your proposed solution did not help using Julia 1.1.0 on Ubuntu 18.04. Julia plots only display in a separate window at command line inside the julia shell but not when calling a .jl script. Nothing displays and no error is raised.

I attempted setting backend with gr() even gui() in script to no avail. Also, as you proposed I tried wrapping one and two display() (the latter of which outputs nothing in console). Still no plot appears. Should I open a new issue with reproducible example? Are there similar issues with confirmed solutions?

@daschw
Copy link
Member

daschw commented Mar 25, 2019

Oh, I think, I did not correctly understand the issue in the first place.
The display window is closed again because julia closes again after executing julia path/to/script.jl, I guess.
You can either start julia, and run the script from the REPL with include("path/to/script.jl"), or you add a saving command in the script, and inspect the image afterwards.

@ParfaitG
Copy link

Thanks, @daschw, both suggestions work!

@Fangwq
Copy link

Fangwq commented Apr 6, 2019

I have the same problem. And I think it is inefficient to save the figure and check it out. So I hope this problem can be solved recently.

@daschw
Copy link
Member

daschw commented Apr 6, 2019

And I think it is inefficient to save the figure and check it out.

I agree. That's why I suggest working interactively in the REPL or in Juno.

So I hope this problem can be solved recently

As I wrote above, if you execute julia path/to/script.jl, julia opens, runs the script and closes again. Hence, no julia window remains open. So this will not be fixed. Also, it's not really a Plots issue.

@Fangwq
Copy link

Fangwq commented Apr 6, 2019

@daschw Yeah, you explained it clearly. And I did it successfully. Thanks for your sharing!

The command will keep the julia window remains open. And the figure will show.
julia -i path/to/script.jl

Also, I was wandering if it can be done with shell script without run julia in terminal. All the problem is about how to send a command to the REPL.

Just like that(in shell.sh file. of course, it is wrong answer.):
#! /bin/bash include("path/to/script.jl") | julia

@Fangwq
Copy link

Fangwq commented Apr 6, 2019

@daschw I try the following script. But it quit immediately, too. 😂

! /bin/bash echo 'include("path/to/script.jl")' | julia

@Fangwq
Copy link

Fangwq commented Apr 6, 2019

@daschw Also, I have a question about how to use Plots to draw figure in different canvas. For PyPlot, we can use figure(1), figure(2) to set. How to do that with Plots ?

@mkitti
Copy link
Contributor

mkitti commented Jun 8, 2020

To prevent julia from exiting immediately, add sleep(5) or readline() at the end of the script. readline() will wait for you to push enter.

@williamfgc
Copy link

@mkitti thanks for the answer, that's the expected behavior. Running julia -i ... drops into the REPL.

@vrkansagara
Copy link

readline() will do the stuff

@kidsjtu
Copy link

kidsjtu commented Oct 31, 2023

readline()
simple but useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants