Hello,
Context: I am trying to save a figure to and .eps extension using PyPlot.
Since I am facing some troubles, I prepared two procedures to save the figure that explain the troubles. Procedure 1 works OK. Procedure 2 doesn’t work. I expect someone to help me out in understanding why Procedure 2 doesn’t work and how to fix it. I give the codes and the outputs I get from these codes below. I am running this in Atom + Juno + Win10.
Procedure 1: it consists in just one .jl file, which I called it “plot8.jl” and contains the following code
plot8.jl
using Plots
pyplot()
function plotme()
x = 1:10; y = rand(10,2)
plot(x, y, title = "Two Lines", label = ["Line 1" "Line 2"], lw = 3)
xlabel!("My x label")
ylabel!("My y label")
savefig("plot8.eps")
end
plotme()
After running this code, the file “plot8.eps” is created. So, right.
Procedure 2: it consists in a file called “plot9.jl” and a file called “Plotme.jl”. Both files are in the same directory. “Plotme.jl” contains a module called “Plotme”. The contents of the files are as follows:
plot9.jl
push!(LOAD_PATH, pwd()) # add working directory to the path to be able to find Plotme module
using Plotme: plotme
plotme()
Plotme.jl
module Plotme
using Plots
pyplot()
function plotme()
x = 1:10; y = rand(10,2)
plot(x, y, title = "Two Lines", label = ["Line 1" "Line 2"], lw = 3)
xlabel!("My x label")
ylabel!("My y label")
savefig("plot9.eps")
end
end
For the first time I run “plot9.jl”, I get right at the beginning the following warning:
[ Info: Recompiling stale cache file C:\Users\aaort\.julia\compiled\v1.0\Plotme.ji for Plotme [top-level]
WARNING: eval from module Main to Plotme:
Expr(:block, #= Symbol("C:\Users\aaort\.julia\packages\Plots\y6yik\src\backends.jl"):529 =#, Expr(:import, Expr(:., :PyPlot)), #= Symbol("C:\Users\aaort\.julia\packages\Plots\y6yik\src\backends.jl"):531 =#, Expr(:export, :PyPlot), #= Symbol("C:\Users\aaort\.julia\packages\Plots\y6yik\src\backends.jl"):534 =#, Expr(:call, Expr(:., :PyPlot, :(:ioff))))
** incremental compilation may be broken for this module **
And after that, I get the following error, which I presume, is in regards that pyplot() is not doing the work and instead gr() is used as the backend (I know that GR can’t plot to .eps):
ERROR: LoadError: MethodError: no method matching _show(::IOStream, ::MIME{Symbol("image/eps")}, ::Plots.Plot{Plots.GRBackend})
Closest candidates are:
_show(::IO, ::MIME{Symbol("text/html")}, ::Plots.Plot) at C:\Users\aaort\.julia\packages\Plots\y6yik\src\output.jl:165
_show(::IO, ::MIME{Symbol("text/plain")}, ::Plots.Plot) at C:\Users\aaort\.julia\packages\Plots\y6yik\src\output.jl:206
_show(::IO, ::MIME{Symbol("application/postscript")}, ::Plots.Plot{Plots.GRBackend}) at C:\Users\aaort\.julia\packages\Plots\y6yik\src\backends\gr.jl:1357
...
Stacktrace:
[1] show(::IOStream, ::MIME{Symbol("image/eps")}, ::Plots.Plot{Plots.GRBackend}) at C:\Users\aaort\.julia\packages\Plots\y6yik\src\output.jl:200
[2] eps(::Plots.Plot{Plots.GRBackend}, ::String) at C:\Users\aaort\.julia\packages\Plots\y6yik\src\output.jl:42
[3] savefig(::Plots.Plot{Plots.GRBackend}, ::String) at C:\Users\aaort\.julia\packages\Plots\y6yik\src\output.jl:123
[4] savefig(::String) at C:\Users\aaort\.julia\packages\Plots\y6yik\src\output.jl:125
[5] plotme() at C:\Dropbox\Universidad\codes\Julia\plot_tests\Plotme.jl:11
[6] top-level scope at none:0
in expression starting at C:\Dropbox\Universidad\codes\Julia\plot_tests\plot9.jl:3
How can this issue be fixed if I must go with Procedure 2 rather than Procedure 1?
Thank you!