Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit 60ec2b5

Browse files
authored
fix default resolution and tweak sizes (#721)
1 parent a472953 commit 60ec2b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+238
-233
lines changed

docs/src/backends_and_output.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,19 @@ CairoMakie.activate!(type = "svg")
6767
When you save a CairoMakie figure, you can change the mapping from figure resolution to pixels (when saving to png) or points (when saving to svg or pdf).
6868
This way you can easily scale the resulting image up or down without having to change any plot element sizes.
6969

70-
Just specify `pt_per_unit` when saving vector formats and `px_per_unit` when saving pngs. Both default to 1.
70+
Just specify `pt_per_unit` when saving vector formats and `px_per_unit` when saving pngs.
71+
`px_per_unit` defaults to 1 and `pt_per_unit` defaults to 0.75.
72+
When embedding svgs in websites, `1px` is equivalent to `0.75pt`.
73+
This means that by default, saving a png or an svg results in an embedded image of the same apparent size.
74+
If you require an exact size in `pt`, consider setting `pt_per_unit = 1`.
75+
7176

7277
Here's an example:
7378

7479
```julia
7580
fig = Figure(resolution = (800, 600))
7681

77-
save("normal.pdf", fig) # size = 800 x 600 pt
82+
save("normal.pdf", fig) # size = 600 x 450 pt
7883
save("larger.pdf", fig, pt_per_unit = 2) # size = 1600 x 1200 pt
7984
save("smaller.pdf", fig, pt_per_unit = 0.5) # size = 400 x 300 pt
8085

docs/src/basic-tutorial.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ This is useful as we can then continue with the figure `f` and the heatmap `hm`
292292
using CairoMakie
293293
294294
f, ax, hm = heatmap(randn(20, 20))
295-
Colorbar(f[1, 2], hm, width = 20)
295+
Colorbar(f[1, 2], hm)
296296
f
297297
```
298298

@@ -305,7 +305,7 @@ using CairoMakie
305305
f = Figure()
306306
ax = Axis(f[1, 1])
307307
hm = heatmap!(ax, randn(20, 20))
308-
Colorbar(f[1, 2], hm, width = 20)
308+
Colorbar(f[1, 2], hm)
309309
f
310310
```
311311

@@ -320,7 +320,7 @@ You can pass your axis attributes under the keyword `axis` and your figure attri
320320
using CairoMakie
321321
322322
heatmap(randn(20, 20),
323-
figure = (resolution = (800, 600), backgroundcolor = :pink),
323+
figure = (backgroundcolor = :pink,),
324324
axis = (aspect = 1, xlabel = "x axis", ylabel = "y axis")
325325
)
326326
```

docs/src/figure.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ This object can be used to plot a new axis into a certain layout position in the
5959
using CairoMakie
6060
CairoMakie.activate!() # hide
6161
62-
f = Figure(resolution = (800, 600))
62+
f = Figure()
6363
pos = f[1, 1]
6464
scatter(pos, rand(100, 2))
6565
@@ -81,7 +81,7 @@ Often, a desired plot layout can only be achieved with nesting, and repeatedly i
8181
using CairoMakie
8282
CairoMakie.activate!() # hide
8383
84-
f = Figure(resolution = (800, 600))
84+
f = Figure()
8585
8686
f[1, 1] = Axis(f, title = "I'm not nested")
8787
f[1, 2][1, 1] = Axis(f, title = "I'm nested")
@@ -100,6 +100,25 @@ All nested grid layouts that don't exist yet, but are needed for a nested plotti
100100
value for further manipulation. You can instead retrieve them after the fact with the `content` function, for example,
101101
as explained in the following section.
102102

103+
## Figure padding
104+
105+
You can change the amount of whitespace around the figure content with the keyword `figure_padding`.
106+
This takes either a number for all four sides, or a tuple of four numbers for left, right, bottom, top.
107+
You can also theme this setting with `set_theme!(figure_padding = 30)`, for example.
108+
109+
```@example
110+
using CairoMakie
111+
CairoMakie.activate!() # hide
112+
113+
f = Figure(figure_padding = 1, backgroundcolor = :gray80)
114+
115+
Axis(f[1, 1])
116+
scatter!(1:10)
117+
118+
f
119+
```
120+
121+
103122
## Retrieving Objects From A Figure
104123

105124
Sometimes users are surprised that indexing into a figure does not retrieve the object placed at that position.

docs/src/makielayout/axis.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Here's how you create one
1313
```@example laxis
1414
using CairoMakie
1515
16-
f = Figure(resolution = (1200, 900))
16+
f = Figure()
1717
1818
ax = Axis(f[1, 1], xlabel = "x label", ylabel = "y label",
1919
title = "Title")
@@ -46,7 +46,7 @@ using CairoMakie
4646
CairoMakie.activate!() # hide
4747
AbstractPlotting.inline!(true) # hide
4848
49-
f = Figure(resolution = (1200, 500))
49+
f = Figure()
5050
5151
axs = [Axis(f[1, i]) for i in 1:3]
5252
@@ -78,7 +78,7 @@ using CairoMakie
7878
CairoMakie.activate!() # hide
7979
AbstractPlotting.inline!(true) # hide
8080
81-
f = Figure(resolution = (1200, 900))
81+
f = Figure()
8282
8383
axes = [Axis(f[i, j]) for j in 1:3, i in 1:2]
8484
@@ -108,7 +108,7 @@ using CairoMakie
108108
CairoMakie.activate!() # hide
109109
AbstractPlotting.inline!(true) # hide
110110
111-
f = Figure(resolution = (800, 400))
111+
f = Figure()
112112
113113
lines(f[1, 1], 0..10, sin)
114114
lines(f[1, 2], 0..10, sin, axis = (limits = (0, 10, -1, 1),))
@@ -148,7 +148,7 @@ The default tick type is `LinearTicks(n)`, where `n` is the target number of tic
148148
```@example
149149
using CairoMakie
150150
151-
fig = Figure(resolution = (1200, 900))
151+
fig = Figure()
152152
for (i, n) in enumerate([2, 5, 9])
153153
lines(fig[i, 1], 0..20, sin, axis = (xticks = LinearTicks(n),))
154154
end
@@ -218,7 +218,7 @@ theme = Attributes(
218218
)
219219
220220
fig = with_theme(theme) do
221-
fig = Figure(resolution = (800, 800))
221+
fig = Figure()
222222
axs = [Axis(fig[fldmod1(n, 2)...],
223223
title = "IntervalsBetween($(n+1))",
224224
xminorticks = IntervalsBetween(n+1),
@@ -240,7 +240,7 @@ To hide spines, you can use `hidespines!`.
240240
```@example
241241
using CairoMakie
242242
243-
f = Figure(resolution = (1200, 900))
243+
f = Figure()
244244
245245
ax1 = Axis(f[1, 1], title = "Axis 1")
246246
ax2 = Axis(f[1, 2], title = "Axis 2")
@@ -260,7 +260,7 @@ It's common, e.g., to hide everything but the grid lines in facet plots.
260260
```@example
261261
using CairoMakie
262262
263-
f = Figure(resolution = (1200, 700))
263+
f = Figure()
264264
265265
ax1 = Axis(f[1, 1], title = "Axis 1")
266266
ax2 = Axis(f[1, 2], title = "Axis 2")
@@ -284,7 +284,7 @@ using CairoMakie
284284
285285
data = LinRange(0.01, 0.99, 200)
286286
287-
f = Figure(resolution = (1000, 1000), fontsize = 14)
287+
f = Figure(resolution = (800, 800))
288288
289289
for (i, scale) in enumerate([identity, log10, log2, log, sqrt, AbstractPlotting.logit])
290290
@@ -336,12 +336,12 @@ using FileIO
336336
using Random # hide
337337
Random.seed!(1) # hide
338338
339-
f = Figure(resolution = (1200, 900))
339+
f = Figure()
340340
341341
axes = [Axis(f[i, j]) for i in 1:2, j in 1:3]
342342
tightlimits!.(axes)
343343
344-
img = rotr90(load("../assets/cow.png"))
344+
img = rotr90(load(assetpath("cow.png")))
345345
346346
for ax in axes
347347
image!(ax, img)
@@ -361,8 +361,8 @@ axes[2, 1].aspect = AxisAspect(1)
361361
axes[2, 2].title = "AxisAspect(2)"
362362
axes[2, 2].aspect = AxisAspect(2)
363363
364-
axes[2, 3].title = "AxisAspect(0.5)"
365-
axes[2, 3].aspect = AxisAspect(0.5)
364+
axes[2, 3].title = "AxisAspect(2/3)"
365+
axes[2, 3].aspect = AxisAspect(2/3)
366366
367367
f
368368
```
@@ -450,7 +450,7 @@ separately.
450450
```@example
451451
using CairoMakie
452452
453-
f = Figure(resolution = (1200, 900))
453+
f = Figure()
454454
455455
ax1 = Axis(f[1, 1])
456456
ax2 = Axis(f[1, 2])
@@ -485,7 +485,7 @@ You can change this with the attributes `xaxisposition = :top` and `yaxispositio
485485
```@example
486486
using CairoMakie
487487
488-
f = Figure(resolution = (800, 800))
488+
f = Figure()
489489
490490
for i in 1:2, j in 1:2
491491
Axis(
@@ -508,7 +508,7 @@ Here's an example how to do this with a second y axis on the right.
508508
```@example
509509
using CairoMakie
510510
511-
f = Figure(resolution = (800, 600))
511+
f = Figure()
512512
513513
ax1 = Axis(f[1, 1], yticklabelcolor = :blue)
514514
ax2 = Axis(f[1, 1], yticklabelcolor = :red, yaxisposition = :right)

docs/src/makielayout/box.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ facet plots or when a rectangular placeholder is needed.
1212
using CairoMakie
1313
using ColorSchemes
1414
15-
fig = Figure(resolution = (1200, 900))
15+
fig = Figure()
1616
1717
rects = fig[1:4, 1:6] = [
1818
Box(fig, color = c)

docs/src/makielayout/button.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CairoMakie.activate!()
88
```@example
99
using GLMakie
1010
11-
fig = Figure(resolution = (1200, 900))
11+
fig = Figure()
1212
1313
ax = Axis(fig[1, 1])
1414
fig[2, 1] = buttongrid = GridLayout(tellwidth = false)

docs/src/makielayout/colorbar.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ Here's how you can create Colorbars manually.
1414
```@example
1515
using CairoMakie
1616
17-
fig = Figure(resolution = (1200, 900))
17+
fig = Figure()
1818
1919
Axis(fig[1, 1])
2020
2121
# vertical colorbars
22-
Colorbar(fig[1, 2], width = 25, limits = (0, 10), colormap = :viridis,
22+
Colorbar(fig[1, 2], limits = (0, 10), colormap = :viridis,
2323
flipaxis = false)
24-
Colorbar(fig[1, 3], width = 25, limits = (0, 5),
25-
colormap = cgrad(:Spectral, 5, categorical = true))
26-
Colorbar(fig[1, 4], width = 25, limits = (-1, 1), colormap = :heat,
24+
Colorbar(fig[1, 3], limits = (0, 5),
25+
colormap = cgrad(:Spectral, 5, categorical = true), size = 25)
26+
Colorbar(fig[1, 4], limits = (-1, 1), colormap = :heat,
2727
highclip = :cyan, lowclip = :red, label = "Temperature")
2828
2929
# horizontal colorbars
30-
Colorbar(fig[2, 1], height = 25, limits = (0, 10), colormap = :viridis,
30+
Colorbar(fig[2, 1], limits = (0, 10), colormap = :viridis,
3131
vertical = false)
32-
Colorbar(fig[3, 1], height = 25, limits = (0, 5),
32+
Colorbar(fig[3, 1], limits = (0, 5), size = 25,
3333
colormap = cgrad(:Spectral, 5, categorical = true), vertical = false)
34-
Colorbar(fig[4, 1], height = 25, limits = (-1, 1), colormap = :heat,
34+
Colorbar(fig[4, 1], limits = (-1, 1), colormap = :heat,
3535
label = "Temperature", vertical = false, flipaxis = false,
3636
highclip = :cyan, lowclip = :red)
3737
@@ -47,22 +47,22 @@ xs = LinRange(0, 20, 50)
4747
ys = LinRange(0, 15, 50)
4848
zs = [cos(x) * sin(y) for x in xs, y in ys]
4949
50-
fig = Figure(resolution = (1200, 900))
50+
fig = Figure()
5151
5252
ax, hm = heatmap(fig[1, 1][1, 1], xs, ys, zs)
53-
Colorbar(fig[1, 1][1, 2], hm, width = 20)
53+
Colorbar(fig[1, 1][1, 2], hm)
5454
5555
ax, hm = heatmap(fig[1, 2][1, 1], xs, ys, zs, colormap = :grays,
5656
colorrange = (-0.75, 0.75), highclip = :red, lowclip = :blue)
57-
Colorbar(fig[1, 2][1, 2], hm, width = 20)
57+
Colorbar(fig[1, 2][1, 2], hm)
5858
5959
ax, hm = contourf(fig[2, 1][1, 1], xs, ys, zs,
6060
levels = -1:0.25:1, colormap = :heat)
61-
Colorbar(fig[2, 1][1, 2], hm, width = 20, ticks = -1:0.25:1)
61+
Colorbar(fig[2, 1][1, 2], hm, ticks = -1:0.25:1)
6262
6363
ax, hm = contourf(fig[2, 2][1, 1], xs, ys, zs,
6464
colormap = :Spectral, levels = [-1, -0.5, -0.25, 0, 0.25, 0.5, 1])
65-
Colorbar(fig[2, 2][1, 2], hm, width = 20, ticks = -1:0.25:1)
65+
Colorbar(fig[2, 2][1, 2], hm, ticks = -1:0.25:1)
6666
6767
fig
6868
```

docs/src/makielayout/gridlayout.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ scene, layout = layoutscene(resolution = (1200, 900))
4141
4242
layout[1, 1] = Axis(scene, title = "My column has size Relative(2/3)")
4343
layout[1, 2] = Axis(scene, title = "My column has size Auto()")
44-
layout[1, 3] = Colorbar(scene, width = 30)
44+
layout[1, 3] = Colorbar(scene)
4545
4646
colsize!(layout, 1, Relative(2/3))
4747
@@ -267,7 +267,7 @@ columns respectively.
267267
```@example spacing
268268
using CairoMakie
269269
270-
fig = Figure(resolution = (1200, 900))
270+
fig = Figure()
271271
272272
axs = [Axis(fig[i, j]) for i in 1:3, j in 1:3]
273273
axs[1, 1].title = "Group A"

docs/src/makielayout/intervalslider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using CairoMakie # hide
2525
AbstractPlotting.inline!(true) # hide
2626
CairoMakie.activate!() # hide
2727
28-
f = Figure(resolution = (800, 800))
28+
f = Figure()
2929
Axis(f[1, 1], limits = (0, 1, 0, 1))
3030
3131
rs_h = IntervalSlider(f[2, 1], range = LinRange(0, 1, 1000),

docs/src/makielayout/label.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ so rows and columns in a GridLayout can shrink to the appropriate width or heigh
1111
```@example
1212
using CairoMakie
1313
14-
fig = Figure(resolution = (1200, 900))
14+
fig = Figure()
1515
1616
fig[1:2, 1:3] = [Axis(fig) for _ in 1:6]
1717

0 commit comments

Comments
 (0)