Need help with very basic plotting

Hello,

I am trying to learn Julia. When I type in the basic plotting example given at
Tutorial · Plots, namely the code below copied directly
from the link given above.

import Pkg; Pkg.add(“Plots”)
using Plots
x = 1:10; y = rand(10); # These are the plotting data
plot(x, y)

I obtain no plot and the following error.

Error evaluating PlotExampleDoesNotWork.jl

LoadError: UndefVarError: plot not defined

in expression starting at /private/tmp/PlotExampleDoesNotWork.jl:4

top-level scope at PlotExampleDoesNotWork.jl:4

include_string(::Function, ::Module, ::String, ::String) at loading.jl:1088

I get the same error with or without the first line: import Pkg; Pkg.add(“Plots”)

What am I missing ?

Thank you and my apologies for such a basic question.

It appears that you tried to run “julia /private/tmp/PlotExampleDoesNotWork.jl”. I recommend running this in the REPL line by line. Just run “julia” first, then type in the commands.

The problem is that this is going to show the plot and then prompt close it if it works.

You only need to use import Pkg; Pkg.add("Plots") once.

Is the error you posted the entire error? It looks like a line prior to plot may have failed. I’m also worried about the quotes here since the copy and pasted version has funny quotes. That might just be the Discourse forum software though.

What happens if you only run using Plots? Is there an error?

Hi @Jcort you could also look at using a simple Pluto notebook . Start a REPL by using the julia command

using Pkg
Pkg.add(“Pluto”)
using Pluto
Pluto.run()

Your browser will open.
Click on Sample Notebooks
Choose Plots.jl
You can play around by changing the contents of a cell - for instance changing the number of apples for a year. Or changing the axis names for a plot.
Press shift-return to run a cell

Thank you MKITTI ! I did as you suggested, opening Julia 1.5.3 in a terminal window and proceeding to execute the four lines of Julia code in my original post. That did work !

Originally I was running the code in the JuliaPro 1.5.3-1 atom environment. The error message in my original post was cut & pasted from the error message that pops up in the JuliaPro atom environment.

I find it odd that the Julia terminal version worked when the JuliaPro version throws an error. One clue as to the problem with JuliaPro is that in exploring other plotting packages in the terminal version of Julia, adding the packages using pkg, and then returning to the terminal Julia to rerun the original plotting code given in my original post, I now obtained an error, namely

julia> plot(x, y)
WARNING: both Plots and Pandas export “plot”; uses of it in module Main must be qualified
ERROR: UndefVarError: plot not defined
Stacktrace:
[1] top-level scope at REPL[152]:1

This is similar to the error in JuliaPro, with the exception of the Warning line which is absent in the JuliaPro error message. With this latest knowledge in hand, adding a preamble of Plots to the plot command in the terminal Julia window version as well as in the JuliaPro code, namely using Plots.plot(x,y) and keeping the remaining three lines of code the same, yields plots in both environments. I find it interesting that the JuliaPro environment did not produce, as far as I noted, the warning message about the collision of the plot command between the Plots package and the Pandas package. It is possible that I had loaded the Pandas package in my JuliaPro explorations before I tried the plotting example in JuliaPro and that was responsible for the failure of the original posted code to run.

Thank you MKITTI, as well as Johnh, for so promptly replying with helpful suggestions. I consider my situation resolved ! Thank you for making learning Julia a pleasant and enjoyable experience !