Skip to content

Commit

Permalink
Support removing colorbar ticks in GR and PGFPlotsX (#4704)
Browse files Browse the repository at this point in the history
* Support removing colorbar ticks, rearrange assembly of colorbar style arguments in PGFPlotsX

* Support removing colorbar ticks in GR

* Prettyness?
  • Loading branch information
ivan-boikov committed Mar 24, 2023
1 parent fbdaa89 commit a16a21a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/backends/gr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,13 @@ function gr_draw_colorbar(cbar::GRColorbar, sp::Subplot, vp::GRViewport)
end
end

z_tick = 0.5GR.tick(z_min, z_max)
gr_set_line(1, :solid, plot_color(:black), sp)
(yscale = sp[:colorbar_scale]) _logScales && GR.setscale(gr_y_log_scales[yscale])
# signature: gr.axes(x_tick, y_tick, x_org, y_org, major_x, major_y, tick_size)
GR.axes(0, z_tick, x_max, z_min, 0, 1, gr_colorbar_tick_size[])
if _has_ticks(sp[:colorbar_ticks])
z_tick = 0.5GR.tick(z_min, z_max)
gr_set_line(1, :solid, plot_color(:black), sp)
(yscale = sp[:colorbar_scale]) _logScales && GR.setscale(gr_y_log_scales[yscale])
# signature: gr.axes(x_tick, y_tick, x_org, y_org, major_x, major_y, tick_size)
GR.axes(0, z_tick, x_max, z_min, 0, 1, gr_colorbar_tick_size[])
end

title = gr_colorbar_title(sp)
gr_set_font(title.font, sp; halign = :center, valign = :top)
Expand Down
28 changes: 18 additions & 10 deletions src/backends/pgfplotsx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,32 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
if hascolorbar(sp)
formatter = latex_formatter(sp[:colorbar_formatter])
cticks = curly(join(get_colorbar_ticks(sp; formatter = formatter)[1], ','))
colorbar_style = if sp[:colorbar] === :top
letter = sp[:colorbar] === :top ? :x : :y

colorbar_style = push!(
Options("$(letter)label" => sp[:colorbar_title]),
"$(letter)label style" => pgfx_get_colorbar_title_style(sp),
"$(letter)tick" => cticks,
"$(letter)ticklabel style" => pgfx_get_colorbar_ticklabel_style(sp),
)

if sp[:colorbar] === :top
push!(
Options("xlabel" => sp[:colorbar_title]),
"xlabel style" => pgfx_get_colorbar_title_style(sp),
colorbar_style,
"at" => "(0.5, 1.05)",
"anchor" => "south",
"xtick" => cticks,
"xticklabel pos" => "upper",
"xticklabel style" => pgfx_get_colorbar_ticklabel_style(sp),
)
else
end

if !_has_ticks(sp[:colorbar_ticks])
push!(
Options("ylabel" => sp[:colorbar_title]),
"ylabel style" => pgfx_get_colorbar_title_style(sp),
"ytick" => cticks,
"yticklabel style" => pgfx_get_colorbar_ticklabel_style(sp),
colorbar_style,
"$(letter)tick style" => "{draw=none}",
"$(letter)ticklabels" => "{,,}",
)
end

push!(
axis_opt,
"colorbar $(pgfx_get_colorbar_pos(sp[:colorbar]))" => nothing,
Expand Down

0 comments on commit a16a21a

Please sign in to comment.