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

Commit

Permalink
fix default resolution and tweak sizes (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel authored Apr 30, 2021
1 parent a472953 commit 60ec2b5
Show file tree
Hide file tree
Showing 44 changed files with 238 additions and 233 deletions.
9 changes: 7 additions & 2 deletions docs/src/backends_and_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ CairoMakie.activate!(type = "svg")
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).
This way you can easily scale the resulting image up or down without having to change any plot element sizes.

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


Here's an example:

```julia
fig = Figure(resolution = (800, 600))

save("normal.pdf", fig) # size = 800 x 600 pt
save("normal.pdf", fig) # size = 600 x 450 pt
save("larger.pdf", fig, pt_per_unit = 2) # size = 1600 x 1200 pt
save("smaller.pdf", fig, pt_per_unit = 0.5) # size = 400 x 300 pt

Expand Down
6 changes: 3 additions & 3 deletions docs/src/basic-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ This is useful as we can then continue with the figure `f` and the heatmap `hm`
using CairoMakie
f, ax, hm = heatmap(randn(20, 20))
Colorbar(f[1, 2], hm, width = 20)
Colorbar(f[1, 2], hm)
f
```

Expand All @@ -305,7 +305,7 @@ using CairoMakie
f = Figure()
ax = Axis(f[1, 1])
hm = heatmap!(ax, randn(20, 20))
Colorbar(f[1, 2], hm, width = 20)
Colorbar(f[1, 2], hm)
f
```

Expand All @@ -320,7 +320,7 @@ You can pass your axis attributes under the keyword `axis` and your figure attri
using CairoMakie
heatmap(randn(20, 20),
figure = (resolution = (800, 600), backgroundcolor = :pink),
figure = (backgroundcolor = :pink,),
axis = (aspect = 1, xlabel = "x axis", ylabel = "y axis")
)
```
Expand Down
23 changes: 21 additions & 2 deletions docs/src/figure.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ This object can be used to plot a new axis into a certain layout position in the
using CairoMakie
CairoMakie.activate!() # hide
f = Figure(resolution = (800, 600))
f = Figure()
pos = f[1, 1]
scatter(pos, rand(100, 2))
Expand All @@ -81,7 +81,7 @@ Often, a desired plot layout can only be achieved with nesting, and repeatedly i
using CairoMakie
CairoMakie.activate!() # hide
f = Figure(resolution = (800, 600))
f = Figure()
f[1, 1] = Axis(f, title = "I'm not nested")
f[1, 2][1, 1] = Axis(f, title = "I'm nested")
Expand All @@ -100,6 +100,25 @@ All nested grid layouts that don't exist yet, but are needed for a nested plotti
value for further manipulation. You can instead retrieve them after the fact with the `content` function, for example,
as explained in the following section.

## Figure padding

You can change the amount of whitespace around the figure content with the keyword `figure_padding`.
This takes either a number for all four sides, or a tuple of four numbers for left, right, bottom, top.
You can also theme this setting with `set_theme!(figure_padding = 30)`, for example.

```@example
using CairoMakie
CairoMakie.activate!() # hide
f = Figure(figure_padding = 1, backgroundcolor = :gray80)
Axis(f[1, 1])
scatter!(1:10)
f
```


## Retrieving Objects From A Figure

Sometimes users are surprised that indexing into a figure does not retrieve the object placed at that position.
Expand Down
32 changes: 16 additions & 16 deletions docs/src/makielayout/axis.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Here's how you create one
```@example laxis
using CairoMakie
f = Figure(resolution = (1200, 900))
f = Figure()
ax = Axis(f[1, 1], xlabel = "x label", ylabel = "y label",
title = "Title")
Expand Down Expand Up @@ -46,7 +46,7 @@ using CairoMakie
CairoMakie.activate!() # hide
AbstractPlotting.inline!(true) # hide
f = Figure(resolution = (1200, 500))
f = Figure()
axs = [Axis(f[1, i]) for i in 1:3]
Expand Down Expand Up @@ -78,7 +78,7 @@ using CairoMakie
CairoMakie.activate!() # hide
AbstractPlotting.inline!(true) # hide
f = Figure(resolution = (1200, 900))
f = Figure()
axes = [Axis(f[i, j]) for j in 1:3, i in 1:2]
Expand Down Expand Up @@ -108,7 +108,7 @@ using CairoMakie
CairoMakie.activate!() # hide
AbstractPlotting.inline!(true) # hide
f = Figure(resolution = (800, 400))
f = Figure()
lines(f[1, 1], 0..10, sin)
lines(f[1, 2], 0..10, sin, axis = (limits = (0, 10, -1, 1),))
Expand Down Expand Up @@ -148,7 +148,7 @@ The default tick type is `LinearTicks(n)`, where `n` is the target number of tic
```@example
using CairoMakie
fig = Figure(resolution = (1200, 900))
fig = Figure()
for (i, n) in enumerate([2, 5, 9])
lines(fig[i, 1], 0..20, sin, axis = (xticks = LinearTicks(n),))
end
Expand Down Expand Up @@ -218,7 +218,7 @@ theme = Attributes(
)
fig = with_theme(theme) do
fig = Figure(resolution = (800, 800))
fig = Figure()
axs = [Axis(fig[fldmod1(n, 2)...],
title = "IntervalsBetween($(n+1))",
xminorticks = IntervalsBetween(n+1),
Expand All @@ -240,7 +240,7 @@ To hide spines, you can use `hidespines!`.
```@example
using CairoMakie
f = Figure(resolution = (1200, 900))
f = Figure()
ax1 = Axis(f[1, 1], title = "Axis 1")
ax2 = Axis(f[1, 2], title = "Axis 2")
Expand All @@ -260,7 +260,7 @@ It's common, e.g., to hide everything but the grid lines in facet plots.
```@example
using CairoMakie
f = Figure(resolution = (1200, 700))
f = Figure()
ax1 = Axis(f[1, 1], title = "Axis 1")
ax2 = Axis(f[1, 2], title = "Axis 2")
Expand All @@ -284,7 +284,7 @@ using CairoMakie
data = LinRange(0.01, 0.99, 200)
f = Figure(resolution = (1000, 1000), fontsize = 14)
f = Figure(resolution = (800, 800))
for (i, scale) in enumerate([identity, log10, log2, log, sqrt, AbstractPlotting.logit])
Expand Down Expand Up @@ -336,12 +336,12 @@ using FileIO
using Random # hide
Random.seed!(1) # hide
f = Figure(resolution = (1200, 900))
f = Figure()
axes = [Axis(f[i, j]) for i in 1:2, j in 1:3]
tightlimits!.(axes)
img = rotr90(load("../assets/cow.png"))
img = rotr90(load(assetpath("cow.png")))
for ax in axes
image!(ax, img)
Expand All @@ -361,8 +361,8 @@ axes[2, 1].aspect = AxisAspect(1)
axes[2, 2].title = "AxisAspect(2)"
axes[2, 2].aspect = AxisAspect(2)
axes[2, 3].title = "AxisAspect(0.5)"
axes[2, 3].aspect = AxisAspect(0.5)
axes[2, 3].title = "AxisAspect(2/3)"
axes[2, 3].aspect = AxisAspect(2/3)
f
```
Expand Down Expand Up @@ -450,7 +450,7 @@ separately.
```@example
using CairoMakie
f = Figure(resolution = (1200, 900))
f = Figure()
ax1 = Axis(f[1, 1])
ax2 = Axis(f[1, 2])
Expand Down Expand Up @@ -485,7 +485,7 @@ You can change this with the attributes `xaxisposition = :top` and `yaxispositio
```@example
using CairoMakie
f = Figure(resolution = (800, 800))
f = Figure()
for i in 1:2, j in 1:2
Axis(
Expand All @@ -508,7 +508,7 @@ Here's an example how to do this with a second y axis on the right.
```@example
using CairoMakie
f = Figure(resolution = (800, 600))
f = Figure()
ax1 = Axis(f[1, 1], yticklabelcolor = :blue)
ax2 = Axis(f[1, 1], yticklabelcolor = :red, yaxisposition = :right)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/makielayout/box.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ facet plots or when a rectangular placeholder is needed.
using CairoMakie
using ColorSchemes
fig = Figure(resolution = (1200, 900))
fig = Figure()
rects = fig[1:4, 1:6] = [
Box(fig, color = c)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/makielayout/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CairoMakie.activate!()
```@example
using GLMakie
fig = Figure(resolution = (1200, 900))
fig = Figure()
ax = Axis(fig[1, 1])
fig[2, 1] = buttongrid = GridLayout(tellwidth = false)
Expand Down
26 changes: 13 additions & 13 deletions docs/src/makielayout/colorbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ Here's how you can create Colorbars manually.
```@example
using CairoMakie
fig = Figure(resolution = (1200, 900))
fig = Figure()
Axis(fig[1, 1])
# vertical colorbars
Colorbar(fig[1, 2], width = 25, limits = (0, 10), colormap = :viridis,
Colorbar(fig[1, 2], limits = (0, 10), colormap = :viridis,
flipaxis = false)
Colorbar(fig[1, 3], width = 25, limits = (0, 5),
colormap = cgrad(:Spectral, 5, categorical = true))
Colorbar(fig[1, 4], width = 25, limits = (-1, 1), colormap = :heat,
Colorbar(fig[1, 3], limits = (0, 5),
colormap = cgrad(:Spectral, 5, categorical = true), size = 25)
Colorbar(fig[1, 4], limits = (-1, 1), colormap = :heat,
highclip = :cyan, lowclip = :red, label = "Temperature")
# horizontal colorbars
Colorbar(fig[2, 1], height = 25, limits = (0, 10), colormap = :viridis,
Colorbar(fig[2, 1], limits = (0, 10), colormap = :viridis,
vertical = false)
Colorbar(fig[3, 1], height = 25, limits = (0, 5),
Colorbar(fig[3, 1], limits = (0, 5), size = 25,
colormap = cgrad(:Spectral, 5, categorical = true), vertical = false)
Colorbar(fig[4, 1], height = 25, limits = (-1, 1), colormap = :heat,
Colorbar(fig[4, 1], limits = (-1, 1), colormap = :heat,
label = "Temperature", vertical = false, flipaxis = false,
highclip = :cyan, lowclip = :red)
Expand All @@ -47,22 +47,22 @@ xs = LinRange(0, 20, 50)
ys = LinRange(0, 15, 50)
zs = [cos(x) * sin(y) for x in xs, y in ys]
fig = Figure(resolution = (1200, 900))
fig = Figure()
ax, hm = heatmap(fig[1, 1][1, 1], xs, ys, zs)
Colorbar(fig[1, 1][1, 2], hm, width = 20)
Colorbar(fig[1, 1][1, 2], hm)
ax, hm = heatmap(fig[1, 2][1, 1], xs, ys, zs, colormap = :grays,
colorrange = (-0.75, 0.75), highclip = :red, lowclip = :blue)
Colorbar(fig[1, 2][1, 2], hm, width = 20)
Colorbar(fig[1, 2][1, 2], hm)
ax, hm = contourf(fig[2, 1][1, 1], xs, ys, zs,
levels = -1:0.25:1, colormap = :heat)
Colorbar(fig[2, 1][1, 2], hm, width = 20, ticks = -1:0.25:1)
Colorbar(fig[2, 1][1, 2], hm, ticks = -1:0.25:1)
ax, hm = contourf(fig[2, 2][1, 1], xs, ys, zs,
colormap = :Spectral, levels = [-1, -0.5, -0.25, 0, 0.25, 0.5, 1])
Colorbar(fig[2, 2][1, 2], hm, width = 20, ticks = -1:0.25:1)
Colorbar(fig[2, 2][1, 2], hm, ticks = -1:0.25:1)
fig
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/makielayout/gridlayout.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ scene, layout = layoutscene(resolution = (1200, 900))
layout[1, 1] = Axis(scene, title = "My column has size Relative(2/3)")
layout[1, 2] = Axis(scene, title = "My column has size Auto()")
layout[1, 3] = Colorbar(scene, width = 30)
layout[1, 3] = Colorbar(scene)
colsize!(layout, 1, Relative(2/3))
Expand Down Expand Up @@ -267,7 +267,7 @@ columns respectively.
```@example spacing
using CairoMakie
fig = Figure(resolution = (1200, 900))
fig = Figure()
axs = [Axis(fig[i, j]) for i in 1:3, j in 1:3]
axs[1, 1].title = "Group A"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/makielayout/intervalslider.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using CairoMakie # hide
AbstractPlotting.inline!(true) # hide
CairoMakie.activate!() # hide
f = Figure(resolution = (800, 800))
f = Figure()
Axis(f[1, 1], limits = (0, 1, 0, 1))
rs_h = IntervalSlider(f[2, 1], range = LinRange(0, 1, 1000),
Expand Down
2 changes: 1 addition & 1 deletion docs/src/makielayout/label.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ so rows and columns in a GridLayout can shrink to the appropriate width or heigh
```@example
using CairoMakie
fig = Figure(resolution = (1200, 900))
fig = Figure()
fig[1:2, 1:3] = [Axis(fig) for _ in 1:6]
Expand Down
6 changes: 3 additions & 3 deletions docs/src/makielayout/layoutables.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using CairoMakie
CairoMakie.activate!() # hide
AbstractPlotting.inline!(true) # hide
f = Figure(resolution = (800, 600))
f = Figure()
ax = Axis(f[1, 1])
f
```
Expand All @@ -40,7 +40,7 @@ using CairoMakie
CairoMakie.activate!() # hide
AbstractPlotting.inline!(true) # hide
scene, layout = layoutscene(resolution = (800, 600))
scene, layout = layoutscene()
ax = layout[1, 1] = Axis(scene)
scene
```
Expand All @@ -59,7 +59,7 @@ using CairoMakie
CairoMakie.activate!() # hide
AbstractPlotting.inline!(true) # hide
f = Figure(resolution = (800, 600))
f = Figure()
Axis(f, bbox = BBox(100, 300, 100, 500), title = "Axis 1")
Axis(f, bbox = BBox(400, 700, 200, 400), title = "Axis 2")
f
Expand Down
Loading

0 comments on commit 60ec2b5

Please sign in to comment.