How to choose a plotting package?

hi David
thanks, something appeared !
i typed exactly your code

  • running it from the terminal gave nothing
  • running it from Atom neither, except when i pressed Command-J and Command-P where the graphic endly appeared !
    i tried to find to which command this shortcut corresponds, i found “join the lines” in the Edit/Lines menus for Command J and find the file for Command P, i dont really understand but it works.
    may I ask a question ?
    using Plots means that we use Plots, but why, then is plotlyjs() called ?
    in other therms, what is the diffence between using Plots plotlysj() and using PlotlyJS ?

by curiosity, i tried to adapt a former example with your technique :

using Plots
plotlyjs()
function contour1()
    x = y = [-2*pi + 4*pi*i/100 for i in 1:100]
    z = [sin(x[i]) * cos(y[j]) * sin(x[i]*x[i]+y[j]*y[j])/log(x[i]*x[i]+y[j]*y[j]+1)
         for i in 1:100 for j in 1:100]
    z_ = [z[i:i+99] for i in 1:100:10000]
    data = contour(;z=z_, x=x, y=y)
    plot(data)
end
display(contour1())

and then Command J and Command P.
After Command P, an empty “Plots” tab appeared.

Vincent

hi Seb
your link lead me to this url : https://github.com/JunoLab/Atom.jl/pull/76/commits/b4f1c555286fe8729d68fded9a489b223427318f where i found a code that i dont know what to do with
should i type this code in a .jl file and just run it once as if was installing something ?
Also, what is REPL ?
thanks for your answer
Vincent

Plots with plotlyjs() uses the Plots API, so the same code will generally work with other backends as well, meaning you can switch them around. Additionally, Using Plots means you have access to the whole recipe system, which gives you “new plots” that don’t actually exist in PlotlyJS by default, like the ability to plot graphs, grouped bar plots, etc.

And just to be clear: you’re only having a problem in Juno?

using Plots; plotly()
plot(rand(10,10))

should work the first time in the REPL (it’s pretty reliable, not many dependencies there). If it doesn’t, try

Pkg.build("Plots")
using Plots; plotly()
plot(rand(10,10))

(the REPL is the term for “Julia in the terminal”, the most basic way of using Julia. Please type that in directly and not via a script or include just to isolate the problem first.)

Hi Cris
Thank you for the explanation about using Plots

  1. until there, i was not able to produce any graph with any way
  2. now, i tried what you said, copy-pasting your code in the REPL (thank you for the explanation about this). The graph appeared in my default web browser.
    Now, i have copy-pasted the same code into an .jl file and runned it from the terminal, typing :
    julia [path of the file] but nothing appears in the browser.

Vincent

Alright, we’re getting somewhere! Let me explain what’s happening with a script. In Julia, the plotting happens because the plot() command returns a plot object. However, there is a difference between running a command in a script, and running a command in the REPL. In the REPL:

a = 2

automatically returns, while

a = 2;

does not (like MATLAB). However, that would make you have to put ; everywhere in a script, and so

a = 2

does now return a in a script. However, this means that plot(...) doesn’t actually return anything to show in a script.

So the next thing we should do is make sure it works for you inside of a script. Once again, I’ll use Plotly since it should always be working (if you have a working web browser). Now put

using Plots; plotly()
display(plot(rand(10,10)))

inside of a .jl file. Inside of the REPL, do include("filename.jl") (use pwd() to make sure you’re in the right directory, and cd("...") around if you need to). This should display the plot.

Now I am not sure about getting julia filename.jl to work directly from the terminal since Julia will exit when finishing its commands. Maybe that’s why it wasn’t working before? I generally just use Julia interactively (and I suspect many others do too).

hi Cris

plot(rand(10,10))```
works fine now, not only in the REPL but also in a file .jl called the way you said, i.e. with `ìnclude("")` in the REPL.
and : 
```using Plots; plotly()
display(plot(rand(10,10)))```
works fine too this way.

ps i precize that i do as in the terminal, i.e. i just type `include("` and then i drag the file from the finder to the position of the cursor to have the absolute path.

now think i can work…

thanks very much

Vincent

Ps Plotly isn't free ? https://plot.ly/

vincent–

choosing between multiple solutions to the same problem is not unique to plotting or julia. there are numerous logging and benchmarking packages to choose from in julia for example, and other open-source languages like python have similar parallel efforts.

the first thing i do when confronted with such a choice is to check how many people “watch”, “star”, and “fork” each of the packages’ github page. then i click on the graphs tab of each package and see if it is actively maintained (ie there is a steady continuous stream of commits). a third key indicator i look for is how many people are involved, and who specifically they are-- do they also contribute to julia base? lastly, many package authors have attended a JuliaCon to promote their work, and youtube recordings of their talks are available.

it is not clear to me that Plots.jl is “state of the art” given these criteria. i personally prefer Gadfly.

6 Likes

I’m running firefox on linux and the plots on the following page

http://gadflyjl.org/stable/man/plotting.html

are displaying with fonts that are much too large. I also downloaded the latest version for 0.5 and got the same result when I ran the examples.

gadfly problem or firefox problem ?

Do you have the “Minimum font size” setting (it’s found in Preferences under the “Content” tab and “Advanced…” button) set to something other than “None”? Changing that to “None” fixed it for me.

I think that’s the wrong criteria for most users. I think the right criteria is:

  • it always works
  • is fast
  • has lots of features
  • is easily extendable
  • has readily available help

Gadfly satisfies none of those. There have been times where there was no developer working on it, and so I had long periods where it just wouldn’t even precompile on my machine. Gadfly is also notoriously slow. It does not have very many features: many things are very “do it yourself”, if it’s even possible (for example, you can’t do anything 3D with it). I never found it easy to extend, and if you do, you have a huge dependency. Lastly, I don’t know where to quickly find help.

On the other hand, all of these are satisfied by plots. Plots.jl always works for be because, by design, at least one backend will always work. Sure, there are months where PyPlot just won’t work, but then I just switch to Plotly or GR (with the same plotting code) and I’m fine. GR, GLVisualize, etc. backends are super fast, so Plots.jl is very fast (other than its startup time). It has tons of features, including PlotRecipes.jl and StatPlots.jl extension libraries (and things like PlotThemes.jl). You can extend Plots.jl for easy usage with your own package via the recipe system, and this does not make Plots.jl a dependency (only RecipesBase.jl, which is a one macro library). Lastly, if you ever need help, there’s a lively chatroom where people answer questions pretty quickly.

With all of those facts, I don’t see how Gadfly can be called the state of the art. In fact, I find it misleading to point new users towards Gadfly since it doesn’t show Julia in its best light: it’s not feature-filled, fast, and infinitely extendable like you’d expect from a Julia library.

But of course, they’re very different beasts. Plots.jl isn’t trying to build the whole graphics backend: it’s just trying to give you a good plotting experience. And you can tell that 100% of the time has gone towards making the plotting API.

3 Likes

I was also a little confused about plots… [I know of, but wasn’t using Plots]; Should you then, for sure do (not using PlotsJS? neither worked… with the rest)?:

julia> using Plotly
[..]
INFO: Precompiling module PlotlyJS.
WARNING: using Lazy.remove in module AtomShell conflicts with an existing identifier.

None of the examples I tried there work e.g.:

Histograms in Julia [I just needed a quick histogram, not even a plot, Google: “Julia histogram” finds this…]

[..]
julia> response = Plotly.plot(data, ["filename" => "basic-histogram", "fileopt" => "overwrite"])
ERROR: MethodError: no method matching PlotlyJS.Plot{TT<:PlotlyJS.AbstractTrace}(::Array{Array{Pair{String,B},1},1}, ::Array{Pair{String,String},1})
Closest candidates are:
  PlotlyJS.Plot{TT<:PlotlyJS.AbstractTrace}{T<:PlotlyJS.AbstractTrace}(::Array{T<:PlotlyJS.AbstractTrace,1}, ::Any; style) at /home/qwerty/.julia/v0.5/PlotlyJS/src/PlotlyJS.jl:64
  PlotlyJS.Plot{TT<:PlotlyJS.AbstractTrace}(::PlotlyJS.AbstractTrace, ::Any; style) at /home/qwerty/.julia/v0.5/PlotlyJS/src/PlotlyJS.jl:69
  PlotlyJS.Plot{TT<:PlotlyJS.AbstractTrace}{T}(::Any) at sysimg.jl:53
 in #plot#36(::Array{Any,1}, ::Function, ::Array{Array{Pair{String,B},1},1}, ::Vararg{Any,N}) at /home/qwerty/.julia/v0.5/PlotlyJS/src/display.jl:75
 in plot(::Array{Array{Pair{String,B},1},1}, ::Array{Pair{String,String},1}) at /home/qwerty/.julia/v0.5/PlotlyJS/src/display.jl:75

EDIT: I overlooked Getting started with plotly in Julia

I followed the instructions to the letter,* just to make sure (up to then skipped to actual plotting; guess this shouldn’t matter, but indication instructions aer for 0.4?):

julia> Plotly.set_credentials_file({“username”=>“DemoAccount”,“api_key”=>“lr1c37zw81”})
ERROR: syntax: { } vector syntax is discontinued

  • I renamed .julia for now, to get around this: I guess this wouldn’t have worked (and is outdated, conflicts with github Pkg.add recommendation) either (I’ll find correct Pkg.remove…):
julia> Pkg.clone("https://github.com/plotly/Plotly.jl")
INFO: Cloning Plotly from https://github.com/plotly/Plotly.jl
ERROR: Plotly already exists

I want to be sure I’m following (correct?) instructions, before I point out errors ot the people at plot.ly. [Not sure how, can anyone confirm info doesn’t work, and maybe has priviledges to correct?]

10 posts were split to a new topic: UnicodePlots examples; Plotly licensing

On Plots.jl:

Just making one note, while Plots.jl seems awesome (not yet tried… should); you’re comparing apples to an orange.

Plots.jl is a wrapper for many, even I believe Gadfly, before dropped as a backend. Gadfly (and others) are only (a wrapper for) one plotting capability.

Fast must depend on the backend. Not sure about always works for any feature for any backend… but you can switch them. Not sure there’s a lowest common-denominator issue… but at least non-native API(?).

I think it is fair to say that Gadfly and Plots (with backends, which BTW does not include Gadfly) are both state-of-the-art and should be preferred entry points for new users, as most julia users seem to prefer one of these plotting packages. They are really quite different things, I agree (I share @ChrisRackauckas preference for Plots, but that is beside the point). So far an issue with Plots has been that none of the backends are ‘pure’ julia, but GLVisualise is set to change that when it matures :slight_smile:

I really don’t know why the official julialang page should be pointing new users to PyPlot, though. There are lots of good plotting packages for julia (used by themselves or as Plots backends), and I don’t see any reason to prefer PyPlot among those.

Whats wrong with PyPlot? Its a pretty mature package and Matplotlib is a widespread piece of software.

Absolutely nothing. I use it every day. But is there any reason to prefer PyPlot over e.g. GR or PlotlyJS?

It seems to be running joke in the Gitter channel for who has more PyPlot issues. I tend to have PyPlot “unusable” for long periods of times for seemingly random reasons.

The latest in the stream of never-ending PyPlot issues had an easy fix if you wanted to muck with a bunch of things:

The other plotting packages just work? And Plotly is prettier while GR is faster? I just don’t see the point of PyPlot anymore. But maybe that’s just my Plots.jl background talking: I’ve tested all of the different background so often that now I have opinions for which one is best to use around breakfast time.

1 Like

I disagree on the pyplot comments. My experience even is in the other direction lately. In the sense that I often find myself using pyplot as Plots.jl backend in the end, as it gave for those particular purposes the most visually pleasing results (such as this wall of pyplot produced loss-function plots: http://lossesjl.readthedocs.io/en/latest/losses/distance.html). My guess is that plotting is one of those topics where it is really easy to develop strong opinions on.

1 Like

I think all this debate is kinda silly, about which plotting package is the best etc. Are we in high school or something? Of course PGFPlots is the best…

(ref Andrei Alexandrescu - best text editor - YouTube)

8 Likes

I think there is only one way to find out which plotting package is the best: a poll :grinning:

1 Like