I have an array of ages and I want to plot a histogram. The Julia docs have nothing about histograms so following the histogram example here I tried calling the histogram function, but got the error below.
How do I plot a histogram in Julia? I’m using the shell, but could do this in IJulia.
julia> ages
943-element Array{Any,1}:
24
53
23
julia> histogram(ages)
/home/dean/.local/lib/python3.5/site-packages/matplotlib/figure.py:445: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
% get_backend())
What packages are you using? I assume, based on your error message, that you’re using PyPlot and there’s some error related to that. The Plots package uses GR as its default backend and it works well for histograms. I also like to use the Gadfly package. There’s a lot of possible tools to do that in Julia, but you need to give us more information about what yo0u’re doing to help you debug it.
You have to go to the package documentation here, where you can see specific examples for PyPlot. I suggest you try other backends too, as mentioned before, GR is the default and works very well.
Your problem seems related to the tools outside of Julia, so you need to make sure you have GR up and running in your computer. These problems can be frustrating, I know, and I’ve had my share of those, but usually you have to make sure you have the package (GR.jl in this case), and sometimes you have to do ] build GR to make sure everything works. Another useful tool is to use ] test GR, if all tests pass, your package should run.
Installed 1.1.0. Opened new Julia shell:
julia> import Pkg; Pkg.add(“Plots”)
julia> Pkg.add(“PyPlot”)
julia> pyplot()
[ Info: Precompiling PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee]
┌ Warning: No working GUI backend found for matplotlib
└ @ PyPlot ~/.julia/packages/PyPlot/mQXSC/src/init.jl:160
Plots.PyPlotBackend()
julia> histogram(randn(1000), bins=:scott, weights=repeat(1:5, outer=200))
/home/dean/.local/lib/python3.5/site-packages/matplotlib/figure.py:445: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
% get_backend())
julia> pyplot()
┌ Warning: No working GUI backend found for matplotlib
└ @ PyPlot ~/.julia/packages/PyPlot/mQXSC/src/init.jl:160
Plots.PyPlotBackend()
julia> histogram(randn(1000), bins=:scott, weights=repeat(1:5, outer=200))
/home/dean/.local/lib/python3.5/site-packages/matplotlib/figure.py:445: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
% get_backend())
You clearly have a problem with your Python backend, this is not related to Julia. Maybe try Gadfly? As far I know, Gadfly is native Julia and very similar to ggplot2 in R. It had some issues with Julia 1.0, but I think those have been solved.
The @map call turns the array into a table (VegaLite.jl needs the input data as a table).
A little more verbose than the other options mentioned in the text here because it follows a grammar of graphics API, but on the flip side that can also be quite powerful.
Are more intuitive syntaxes for things like this, and trendlines, etc., in the works for VegaLite, or are there philosophical reasons to not go that way?
I get:
julia> histogram(population)
/home/dean/.local/lib/python3.5/site-packages/matplotlib/figure.py:445: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
% get_backend())