0.6.2 Histograms and Finding Good Packages For Plotting

dear julia experts—I am running into some issues with plotting simple histograms, as of mid-Feb 2018, julia 0.6.2, macOS.

Yes, I did RTFMs. For example, I added Pkg.add("PyPlot"). Then I did 'using PyPlot, which led to a good number of installation prompts, culminating in ERROR: InitError: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name). This was fixable with Conda.update()`.

ready. now,

using Distributions;  using PyPlot;
nm= rand( Normal(0,1), 10000 );
h = Histogram( nm )
p = PyPlot.plt.hist(nm, 30)  ## accdg to web docs

but this tells me that there is no hist field. Nothing like PyPlot.hist(x) or PyPlot.plot( h ) or anything like it worked, either. I tried package StatPlots, package Plots with StatsBase, Plotly, and hosts of other combinations. the best I got was no error, but just empty plots. this must be easy. what is the recommended way to draw histograms now and in julia 1.0?

pointers appreciated. /iaw

Plotting simple histograms is straightforward with Gaston. All it requires is gnuplot.

I’m not sure if gnuplot has fixed the aqua term – this is a nice, MacOS-only graphical terminal that stopped working some time ago. If you decide to try Gaston, you may attempt

set(terminal="aqua")

prior to plotting. If it doesn’t work, please let me know and try either "qt", "wxt" or "x11" instead.

If you want to stay with PyPlot, this seems to work (PyPlot v2.3.2, Matplotlib 2.0.2):

PyPlot.plt[:hist](nm,30)

Edit: I noticed that this is actually described in the package README file.

With the Plots package you can do histogram(nm).

3 Likes

I don’t have any preferences for one package, but I really want to stay with julia. Is there a “more” quasi-official long-term graphing/plotting package? From the name, is juliaplots the way to go?

I don’t think there is a canonical solution: from JuliaPlots you could use Plots for regular plots and StatPlots for statistical plots. My personal favorite is the GR backend: it is the default, but needs to be installed separately with Pkg.add("GR"). You should find a reasonable amount of tutorials and documentation to get started.

1 Like

But both PyPlot and Gadfly are quasi-official solutions as well. I think the current best advice is to go with the one that feels best for you. At the moment, many people do seem to use Plots + GR though. You can find a somewhat lengthy discussion here: Where is actual development in Plotting?

thanks, everyone. I can now plot histograms.

how would I know that PyPlot and Gadfly are quasi-official? or Plots + GR?

Good question. The julialang web page used to state that, but the page was removed. Maybe the correct answer is that there explicitly isn’t an official package.

and you have been following julia for a while. now put yourself into the shoes of someone starting out who is trying to understand the lay of the land …

1 Like

In practice it’s generally a good idea to check the number of stars and contributors of a package and see when is the latest commit. In this case Plots has 67 contributors and over 400 stars and last commit is from 6 days ago, so it should be a reasonably safe bet. Same applies for PyPlot and Gadfly (even though with different numbers).

1 Like

What does quasi-official even mean when there’s no committee making that decision, and everyone makes the decision which is right for themselves?

Plots + GR tends to be the one that people use for tutorials, and it’s the most flexible. The recipe system means there’s a lot of other libraries which generate Plots.jl plots. Because of this ecosystem integration, it’s what I would recommend to newcomers. But it does have flaws. PyPlot is flexible as well, but you generally have to “do more yourself”. Gadfly exists too but is more restricted in what it can do.

1 Like

where do you usually check? how do you go about checking? at https://pkg.julialang.org/pulse.html ?

so, let’s say I want to learn how to do plotting and histogramming. where do I type in “histogram” and get a list of packages, in order of activity/popularity/etc?

2 Likes

Probably Julia observer is a good place to look for solid packages. You can also see which ones are “trending”. I like to go through what is there to see if there are things that match my usecases. The only caveat is that some old packages may have a lot of stars from the past but they could be unmaintained now (not sure if it’s the case, just a possibility) so I’d recommend quickly checking on the github repo to see when was the last commit. Gadfly, DataFrames and Plots are all in the top 10 most starred, so reasonably easy to find.

5 Likes