Skip to content

Commit c80e4ac

Browse files
committed
Update to use only PyCall (and no PyPlot)
1 parent 3255a3e commit c80e4ac

File tree

6 files changed

+48
-14
lines changed

6 files changed

+48
-14
lines changed

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Julia ProPlot Examples
33

4-
Here you will find some (most?) of the [ProPlot](https://proplot.readthedocs.io/en/latest/index.html) examples from the documentation, but translated to Julia using [PyCall.jl](https://github.com/JuliaPy/PyCall.jl) and [PyPlot.jl](https://github.com/JuliaPy/PyPlot.jl).
4+
Here you will find some (most?) of the [ProPlot](https://proplot.readthedocs.io/en/latest/index.html) examples from the documentation, but translated to Julia using [PyCall.jl](https://github.com/JuliaPy/PyCall.jl).
55

66
Note you must install ProPlot first. (And probably some other things.)
77

@@ -14,22 +14,28 @@ Click on the images below to be directed to the julia code that produced it.
1414
### Figures and subplots
1515

1616

17-
[<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/b348d0832f657aae4f466ec4e22d733f19bc9f71/Figures-and-subplots-1.svg">
18-
<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/b348d0832f657aae4f466ec4e22d733f19bc9f71/Figures-and-subplots-2.svg">
19-
<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/b348d0832f657aae4f466ec4e22d733f19bc9f71/Figures-and-subplots-3.svg">](basics/Figures-and-subplots.jl)
17+
[<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/8dc99126f838f4ed4cb1eaec5c9286caaa89b44e/Figures-and-subplots-1.svg">
18+
<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/8dc99126f838f4ed4cb1eaec5c9286caaa89b44e/Figures-and-subplots-2.svg">
19+
<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/8dc99126f838f4ed4cb1eaec5c9286caaa89b44e/Figures-and-subplots-3.svg">](basics/Figures-and-subplots.jl)
2020

2121
### Formatting subplots
2222

23-
[<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/b348d0832f657aae4f466ec4e22d733f19bc9f71/Formatting-subplots.svg">](basics/Formatting-subplots.jl)
23+
[<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/8dc99126f838f4ed4cb1eaec5c9286caaa89b44e/Formatting-subplots.svg">](basics/Formatting-subplots.jl)
2424

2525
### Changing rc settings
2626

27-
[<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/b348d0832f657aae4f466ec4e22d733f19bc9f71/Changing-rc-settings.svg">](basics/Changing-rc-settings.jl)
27+
[<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/8dc99126f838f4ed4cb1eaec5c9286caaa89b44e/Changing-rc-settings.svg">](basics/Changing-rc-settings.jl)
2828

2929
### Subplot grids
3030

31-
[<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/b348d0832f657aae4f466ec4e22d733f19bc9f71/Subplot-grids.svg">](basics/Subplot-grids.jl)
31+
[<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/8dc99126f838f4ed4cb1eaec5c9286caaa89b44e/Subplot-grids.svg">](basics/Subplot-grids.jl)
3232

33+
## Subplots features
34+
35+
### Automatic figure sizing
36+
37+
[<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/8dc99126f838f4ed4cb1eaec5c9286caaa89b44e/Automatic-figure-sizing-1.svg.svg">
38+
<img src="https://gist.github.com/briochemc/205e88cd3bfb13dd8c42c539a32afe28/raw/8dc99126f838f4ed4cb1eaec5c9286caaa89b44e/Automatic-figure-sizing-2.svg">](subplots/Automatic-figure-sizing.jl)
3339

3440
## Notes
3541

@@ -39,4 +45,4 @@ Click on the images below to be directed to the julia code that produced it.
3945

4046
1. `f, axs = proplot.subplots()` returns a vector of axes, even if you specify multiple columns, so that you need to reshape (and transpose) the `axs` array to get access to the axes in the "expected" way.
4147

42-
1. I saved the images via `savefig("X.png")`, which did not preserve some features.
48+
1. I saved the images via `f.savefig("X.svg", transparent=false)`.

basics/Changing-rc-settings.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# Import proplot using PyCall
66
using PyCall
77
proplot = pyimport("proplot")
8-
using PyPlot
98

109
# Update global settings in several different ways
1110
proplot.rc.cycle = "colorblind"
@@ -41,3 +40,4 @@ ay.plot(cumsum(rand(100) .- 0.2), color="r", lw=3)
4140

4241
# Reset persistent modifications from head of cell
4342
proplot.rc.reset()
43+
f.savefig("Changing-rc-settings.svg", transparent=false)

basics/Figures-and-subplots.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# Import proplot using PyCall
66
using PyCall
77
proplot = pyimport("proplot")
8-
using PyPlot
98

109
# start of example
1110
data = cumsum(2(rand(100, 5) .- 0.5), dims=1)
@@ -18,6 +17,7 @@ axs[1].format(xticks=20, xtickminor=false)
1817
suptitle="Simple subplot grid", title="Title",
1918
xlabel="x axis", ylabel="y axis"
2019
) for ax in axs]
20+
f.savefig("Figures-and-subplots-1.svg", transparent=false)
2121

2222
# Complex grid
2323
array = [ # the "picture"; 1 == subplot a, 2 == subplot b, etc.
@@ -30,6 +30,7 @@ f, axs = proplot.subplots(array, axwidth=1.8)
3030
xlabel="xlabel", ylabel="ylabel"
3131
) for ax in axs]
3232
axs[3].plot(data, lw=2)
33+
f.savefig("Figures-and-subplots-2.svg", transparent=false)
3334

3435
# Really complex grid
3536
array = [ # the "picture"
@@ -43,4 +44,5 @@ f, axs = proplot.subplots(array, width=5, span=false)
4344
suptitle="Really complex subplot grid",
4445
xlabel="xlabel", ylabel="ylabel", abc=true
4546
) for ax in axs]
46-
axs[1].plot(data, lw=2)
47+
axs[1].plot(data, lw=2)
48+
f.savefig("Figures-and-subplots-3.svg", transparent=false)

basics/Formatting-subplots.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
# Import proplot using PyCall
66
using PyCall
77
proplot = pyimport("proplot")
8-
using PyPlot
98

10-
f, axs = proplot.subplots(ncols=2, nrows=2, share=0, tight=true, axwidth=2.3)
9+
f, axs = proplot.subplots(ncols=2, nrows=2, share=0, tight=true, axwidth=1.7)
1110
axs[1].plot(range(1, 10, length=80), cumsum(rand(80, 5) .- 0.5, dims=1))
1211
[ax.format(
1312
suptitle="Format command demo",
@@ -22,3 +21,4 @@ axs[1].plot(range(1, 10, length=80), cumsum(rand(80, 5) .- 0.5, dims=1))
2221
ytickloc="both", yticklabelloc="both", ygridminor=true,
2322
linewidth=0.8, gridlinewidth=0.8, gridminorlinewidth=0.5,
2423
) for ax in axs]
24+
f.savefig("Formatting-subplots.svg", transparent=false)

basics/Subplot-grids.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# Import proplot using PyCall
66
using PyCall
77
proplot = pyimport("proplot")
8-
using PyPlot
98

109
f, axs = proplot.subplots(ncols=4, nrows=4, axwidth=1.2)
1110
[ax.format(
@@ -24,3 +23,4 @@ axs[1].format(color="black", facecolor="gray5", linewidth=1.4)
2423
for ax in axs[2:end, 2:end]
2524
ax.plot(cumsum(rand(50, 5) .- 0.5, dims=1), cycle="Grays", lw=2)
2625
end
26+
f.savefig("Subplot-grids.svg", transparent=false)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Translating
2+
# https://proplot.readthedocs.io/en/latest/subplots.html#Automatic-figure-sizing
3+
# to Julia
4+
5+
# Import proplot using PyCall
6+
using PyCall
7+
proplot = pyimport("proplot")
8+
#using PyPlot
9+
10+
# Cartopy projections
11+
f, axs = proplot.subplots(ncols=2, nrows=3, proj="robin")
12+
map(x -> x.format(
13+
land=true, landcolor="k",
14+
suptitle="Auto figure sizing with grid of cartopy projections"
15+
), axs)
16+
f.savefig("Automatic-figure-sizing-1.svg", transparent=false)
17+
18+
# Images
19+
f, axs = proplot.subplots(ncols=2, nrows=3)
20+
colors = cumsum(rand(10, 20, 3), dims=3)
21+
colors /= maximum(colors)
22+
[ax.imshow(colors) for ax in axs]
23+
[ax.format(
24+
suptitle="Auto figure sizing with grid of images"
25+
) for ax in axs]
26+
f.savefig("Automatic-figure-sizing-2.svg", transparent=false)

0 commit comments

Comments
 (0)