Skip to content

Commit

Permalink
Merge pull request #57 from MakieOrg/broken_axis
Browse files Browse the repository at this point in the history
Broken axis
  • Loading branch information
lazarusA authored Jan 9, 2025
2 parents 9b21dc5 + 7697264 commit 125c592
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ docs/src/.vitepress/cache
docs/docs_site/.vitepress/dist
docs/docs_site/.vitepress/cache
docs/src/examples

package-lock.json
.cache
dev
test_record
Expand Down
1 change: 1 addition & 0 deletions docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ const viteConfig = defineViteConfig({
{ text: 'line_xlog',link: '/examples/2d/lines/line_xlog' },
{ text: 'line_xylog',link: '/examples/2d/lines/line_xylog' },
{ text: 'line_ylog',link: '/examples/2d/lines/line_ylog' },
{ text: 'line_broken_axis',link: '/examples/2d/lines/line_broken_axis' },
],
},
{
Expand Down
6 changes: 3 additions & 3 deletions docs/src/.vitepress/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ mjx-container > svg {
* -------------------------------------------------------------------------- */

:root {
--vp-c-brand-1: #e4c92a;
--vp-c-brand-2: #e4c92a;
--vp-c-brand-3: #e4c92a;
--vp-c-brand-1: #ca2971;
--vp-c-brand-2: #ca2971;
--vp-c-brand-3: #ca2971;
--vp-c-sponsor: #ca2971;
--vitest-c-sponsor-hover: #c13071;
}
Expand Down
82 changes: 82 additions & 0 deletions examples/2d/lines/line_broken_axis.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# ## broken y axis

# ![](line_broken_y_axis.svg)

using CairoMakie
CairoMakie.activate!(type="svg") #hide

# define some data
x = [1, 2, 3, 4, 5, 6, 7, 8]
y = [1.6022884252337856e-15
1.0982140221904354e-15
5.463801624996023e-15
5.317256161421627e-7
8.476518770185598e-5
0.0005105758346367672
0.006769803152530791
0.0791149895645982]

fig = Figure()
gL = GridLayout(fig[1, 1])

row1 = 1
row2 = 2

ax_top = Axis(gL[1, 1], yscale=log10, ygridvisible=false, xgridvisible=false)
ax_bot = Axis(gL[2, 1], yscale=log10, xlabel="x axis label", ygridvisible=false, xgridvisible=false)

Label(gL[1:2, 1, Left()], "y axis Label", rotation=π / 2, padding=(0, 60, 0, 0))

below_break_min = 1E-16
below_break_max = 1E-14
above_break_min = 1E-6
above_break_max = 1E-1

ax_top_fraction = 0.65
ax_bot_fraction = 1 - ax_top_fraction

below_break = (below_break_min, below_break_max)
above_break = (above_break_min, above_break_max)
lims = Observable((below_break, above_break))
on(lims) do (bottom, top)
ylims!(ax_bot, bottom)
ylims!(ax_top, top)
rowsize!(gL, row1, Auto(ax_top_fraction))
rowsize!(gL, row2, Auto(ax_bot_fraction))
end

hidexdecorations!(ax_top, grid=false)
ax_top.bottomspinevisible = false
ax_bot.topspinevisible = false

linkxaxes!(ax_top, ax_bot)
gap_size = 25
rowgap!(gL, gap_size)

angle_ = pi / 8
linelength = 10

segments = lift(
@lift($(ax_top.yaxis.attributes.endpoints)[1]),
@lift($(ax_bot.yaxis.attributes.endpoints)[2]),
@lift($(ax_top.elements[:yoppositeline][1])[1]),
@lift($(ax_bot.elements[:yoppositeline][1])[2]),
) do p1, p2, p3, p4
ps = Point2f[p1, p2, p3, p4]

map(ps) do p
a = p + Point2f(cos(angle_), sin(angle_)) * 0.5 * linelength
b = p - Point2f(cos(angle_), sin(angle_)) * 0.5 * linelength
(a, b)
end
end

linesegments!(fig.scene, segments, color=:black)

scatterlines!(ax_top, x, y)
scatterlines!(ax_bot, x, y)
hlines!(ax_top, above_break_min, linestyle=:dash, color=:gray)
hlines!(ax_bot, below_break_max, linestyle=:dash, color=:gray)
notify(lims)

save("line_broken_y_axis.svg", current_figure()); # hide

0 comments on commit 125c592

Please sign in to comment.