JuliaInterop / JuliaInterop/JuliaCall
Saving PyPlot figure in julia code chunk in rBookdown
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 287
- Forks
- 43
- PR merge metrics
- No merged PRs in 30d
Description
I can run the following code in Julia 1.2.0 console and it works fine - that is, it saves the figure as expected.
using PyPlot
clf();
ioff();
x1 = collect(0:0.1:2)
x2a = 1 .- 0.5x1
x2b = ifelse.(2 .- 2x1.>=0, 2 .- 2*x1,0)
fig, ax = subplots();
ax.fill_between(x1,x2a,color="red",linewidth=2,label=L"x_{2} \leq 1 - \frac{1}{2}x_{1}",alpha=0.3);
ax.legend(loc="upper right");
ax.fill_between(x1,x2b,color="blue",linewidth=2,label=L"x_{2} \leq 2 - 2x_{1}",alpha=0.3);
ax.legend(loc="upper right");
ax.set_xlabel(L"x_{1}")
ax.set_ylabel(L"x_{2}")
savefig("example-01a.png");
But when I run the same code inside a code chunk in rBookdown with Julia as the engine, the saved chart is blank, only showing the x-axis and y-axis.
using PyPlot
clf();
ioff();
x1 = collect(0:0.1:2)
x2a = 1 .- 0.5*x1
x2b = ifelse.(2 .- 2*x1.>=0, 2 .- 2*x1,0)
fig, ax = subplots();
ax.fill_between(x1,x2a,color="red",linewidth=2,label=L"x_{2} \leq 1 - \frac{1}{2}x_{1}",alpha=0.3);
ax.legend(loc="upper right");
ax.fill_between(x1,x2b,color="blue",linewidth=2,label=L"x_{2} \leq 2 - 2x_{1}",alpha=0.3);
ax.legend(loc="upper right");
ax.set_xlabel(L"x_{1}")
ax.set_ylabel(L"x_{2}")
savefig("example-01a.png");
My apologies if this is a trivial issue, and would appreciate any suggestions to address it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Julia 1.2.0 PyPlot code in an rBookdown Julia code chunk and compare it with running the same code in the Julia console. The payload names no repository file or test, so trace JuliaCall's Julia-engine chunk execution and figure-saving path. Done means the generated example-01a.png contains the plotted filled regions, not only the axes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia, r
- Domain
- data-visualization, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100