ScenTrees.jl icon indicating copy to clipboard operation
ScenTrees.jl copied to clipboard

Use plot recipe instead of pyplot

Open odow opened this issue 5 years ago • 9 comments

Pyplot is a pretty heavy dependency.

An alternative is to write a plotting recipe: https://github.com/JuliaPlots/RecipesBase.jl

This lets you have a very light dependency, and users can use whichever Plots.jl backed they like to plot.

Here's an example in SDDP.jl: https://github.com/odow/SDDP.jl/blob/master/src/visualization/publication_plot.jl

odow avatar Sep 21 '19 16:09 odow

Thank you for this. I will see how possible to rewrite the plotting functions with this

kirui93 avatar Sep 21 '19 17:09 kirui93

Furthermore, when getting ScenTrees.jl, PyPlot yields an error asking to install a system matplotlib:

[ Info: Precompiling ScenTrees [4ec4db44-c288-11e9-3202-272e944f779a]
ERROR: LoadError: LoadError: InitError: PyError (PyImport_ImportModule

The Python package matplotlib could not be found by pyimport. Usually this means
that you did not install matplotlib in the Python version being used by PyCall.

PyCall is currently configured to use the Python version at:

/usr/bin/python3

and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the matplotlib module.

One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV["PYTHON"] to the path/name of the python
executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.

Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia.  As explained in the PyCall documentation,
set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
To install the matplotlib module, you can use `pyimport_conda("matplotlib", PKG)`,
where PKG is the Anaconda package the contains the module matplotlib,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).

) <class 'ModuleNotFoundError'>
ModuleNotFoundError("No module named 'matplotlib'",)

matbesancon avatar Nov 22 '19 17:11 matbesancon

Hello @matbesancon , Have you installed PyPlot.jl?

kirui93 avatar Nov 22 '19 18:11 kirui93

Not globally, it shouldn't be necessary when you install ScenTrees.jl, because the Project.toml automatically tells you what is needed

matbesancon avatar Nov 22 '19 18:11 matbesancon

I did build well PyPlot and checked that everything was okay. I don't know what is the cause of this but I will redo it again

kirui93 avatar Nov 22 '19 18:11 kirui93

Yea, PyPlot is not the Julian way. Consider switching to Plots.jl or Makie.jl in the future as these are not attached to specific backends that only run in the presence of another programming language.

juliohm avatar Nov 22 '19 19:11 juliohm

I am working towards changing that. I had chose PyPlot because it has functionalities that are required for annotating density plots for both scenario trees and scenario lattices. But i will work towards changing to Plots.jl and also considering the RecipeBase.jl already mentioned.

kirui93 avatar Nov 22 '19 19:11 kirui93

I do not consider this blocking for the JOSS review https://github.com/openjournals/joss-reviews/issues/1912, can you simply add a mention that matplotlib is required for now?

matbesancon avatar Nov 22 '19 20:11 matbesancon

@matbesancon Okay I will mention that in the docs for the moment.

kirui93 avatar Nov 23 '19 10:11 kirui93