# Editing fontstyle for colorbar

**URL:** <https://discourse.julialang.org/t/editing-fontstyle-for-colorbar/5967>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [September 19, 2017, 7:54am UTC](https://discourse.julialang.org/t/editing-fontstyle-for-colorbar/5967 "2017-09-19T07:54:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnkurD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ankurd/32/1932_2.png) [@AnkurD](https://discourse.julialang.org/u/AnkurD)\
**Post date:** [September 19, 2017, 7:54am UTC](https://discourse.julialang.org/t/editing-fontstyle-for-colorbar/5967/1 "2017-09-19T07:54:35Z")

</div>

I was trying to adjust the colorbar fonts in my heatmap, but I realized that there is no option to do so through PyPlot (or any other backend for that matter). I could just go back and call matplotlib directly, but that defeats the point when the functionality should exist.

For example, the matplotlib command plt.colorbar().set\_label(label=‘a label’,size=15) could be given as cb:set\_label  
(Currently if you try this Julia throws an error for too many arguments)  
Likewise, the colorbar ticks could be adjusted as follows:  
cb.ax.tick\_params(labelsize=font\_size)-\>cbax:tick\_params

I would try to fix these things myself, but I do not under fully where PyPlot is making explicit calls to matplotlib and how to adjust those. Help with either resolving this or pointing me in the right direction would be appreciated.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 19, 2017, 8:48am UTC](https://discourse.julialang.org/t/editing-fontstyle-for-colorbar/5967/2 "2017-09-19T08:48:28Z")

</div>

When you talk about “backends”, does that mean you’re working with Plots.jl? You only mention PyPlot.

---

<div class="post-metadata">

**Author:** ![AnkurD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ankurd/32/1932_2.png) [@AnkurD](https://discourse.julialang.org/u/AnkurD)\
**Post date:** [September 19, 2017, 11:46pm UTC](https://discourse.julialang.org/t/editing-fontstyle-for-colorbar/5967/3 "2017-09-19T23:46:48Z")

</div>

Correct, I’m trying to use Plots.jl with PyPlot as a backend.

---

<div class="post-metadata">

**Author:** ![AnkurD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ankurd/32/1932_2.png) [@AnkurD](https://discourse.julialang.org/u/AnkurD)\
**Post date:** [September 20, 2017, 1:42am UTC](https://discourse.julialang.org/t/editing-fontstyle-for-colorbar/5967/4 "2017-09-20T01:42:05Z")

</div>

By adding the following lines when the colorbar is created (line 863 in pyplot.jl under backends in the Plots package) I am able to adjust the font size and family of the colorbar tick labels based on the Y-axis fontsize (:ytickfont), though I suppose in the future this should be independent of other axes.

```julia
axis = sp[Symbol(:y,:axis)]
cbax = fig[:add_axes]([0.8,0.1,0.03,0.8], label = string(gensym()))
 cb = fig[:colorbar](handle; cax = cbax, kw...)
 cb[:set_label](sp[:colorbar_title],size=py_dpi_scale(plt, axis[:guidefont].pointsize),family=axis[:guidefont].family)
for lab in cb[:ax][:yaxis][:get_ticklabels]()
       lab[:set_fontsize](py_dpi_scale(plt, axis[:tickfont].pointsize))
       lab[:set_family](axis[:tickfont].family)
 end 

```

Similarly for the colorbar label I use:guidefont as the formatter. This sets the size and font accurately, though I am unsure on efficiency.
