Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latexstring not defined w/ savefig/pyplot #1659

Closed
mortenpi opened this issue Aug 15, 2018 · 12 comments · Fixed by #1664
Closed

latexstring not defined w/ savefig/pyplot #1659

mortenpi opened this issue Aug 15, 2018 · 12 comments · Fixed by #1664

Comments

@mortenpi
Copy link
Contributor

I am seeing the following failure on 0.7 (with Plots.jl on current master):

using Plots
pyplot()

plot(1:3)
yaxis!(:log)
savefig("test.png")
ERROR: LoadError: UndefVarError: latexstring not defined
Stacktrace:
 [1] (::getfield(Plots, Symbol("##470#473")))(::String) at /home/mortenpi/.julia/packages/Plots/LWBTU/src/backends/pyplot.jl:242
 [2] iterate at ./generator.jl:47 [inlined]
 [3] _collect(::Array{String,1}, ::Base.Generator{Array{String,1},getfield(Plots, Symbol("##470#473"))}, ::Base.EltypeUnknown, ::Base.HasShape{1}) at ./array.jl:632
...

Full MWE with manifest etc.

@mkborregaard
Copy link
Member

Would you mind trying to explicitly add and using LaTeXStrings (and then PyCall)?
I think this could be because Plots calls those two packages as well, they are deps of PyPlot but you can't using packages that have only been installed as deps on 1.0.

@mortenpi
Copy link
Contributor Author

mortenpi commented Aug 15, 2018

I have it explicitly added (otherwise already pyplot() doesn't run). But

using Plots
using LaTeXStrings
pyplot()
plot(1:3)
yaxis!(:log)
savefig("test.png")

still fails with the same error.

I was sniffing around a bit in the code I am wondering whether @eval Main is really correct here? Because you would want latexstring to be available in the Plots module, not in Main, no?

Plots.jl/src/backends.jl

Lines 387 to 397 in 2d217ed

function _initialize_backend(::PyPlotBackend)
@eval Main begin
import PyPlot, PyCall
import LaTeXStrings: latexstring
export PyPlot
# we don't want every command to update the figure
PyPlot.ioff()
end
end

Edit: for completeness I also tried with using PyCall -- also no joy.

@mkborregaard
Copy link
Member

Yes it makes sense to eval into Plots, not Main, I think. That code is brand new, it was added by @daschw in #1601 . What happens if you eval into Plots instead?

@mortenpi
Copy link
Contributor Author

If I drop Main from there it works, but you get a warning about a missing dependency:

┌ Warning: Package Plots does not have PyPlot in its dependencies:
│ - If you have Plots checked out for development and have
│   added PyPlot as a dependency but haven't updated your primary
│   environment's manifest file, try `Pkg.resolve()`.
│ - Otherwise you may need to report an issue with Plots
└ Loading PyPlot into Plots from project dependency, future warnings for Plots are suppressed.

Maybe the labelfunc that has the latexstring calls needs a @require around it?

mortenpi added a commit to mortenpi/Plots.jl that referenced this issue Aug 15, 2018
latexstring comes from the LaTeXStrings package, which is conditionally
loaded by pyplot().

Fix JuliaPlots#1659.
@mkborregaard
Copy link
Member

The warning about the missing dependency is spurious and can be ignored - that's because when you change the imports of a deved package you need to run ]resolve under Pkg3.

Let's keep this open even though you made the PR, I'd like to hear @daschw 's opinion about the module to eval into once he gets back from hiking in the mountains :-)

@baggepinnen
Copy link
Contributor

The problem is not only with savefig, I can't display the plot at all if using log-scale.

@mkborregaard
Copy link
Member

What error are you getting? Is this with @mortenpi 's PR checked out?

@baggepinnen
Copy link
Contributor

Same error as reported above. I must admit I have not been able to checkout the PR, I can't figure out how to do :/

@mkborregaard
Copy link
Member

I'd think you should be able to do add https://github.com/mortenpi/Plots.jl#fix-pyplot-savefig , then ]free to get back to the release version.

@baggepinnen
Copy link
Contributor

That fixes it! Thanks a lot, I haven't figured out the new Pkg fully yet.

@mortenpi
Copy link
Contributor Author

@mkborregaard For what it's worth, I don't think the warning is spurious -- Plots doesn't have PyCall / LaTeXStrings in its dependencies, so you should always get the warning when loading them into the Plots module. Requires.jl seems to somehow get around this though.

@mkborregaard
Copy link
Member

Yes Requires should get around that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants