# Scientific Notation in Plots.jl colorbar

**URL:** <https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793>\
**Category:** Visualization\
**Tags:** question, visualization, plots\
**Created:** [March 23, 2021, 3:31pm UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793 "2021-03-23T15:31:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lsterzinger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lsterzinger/32/23208_2.png) [@lsterzinger](https://discourse.julialang.org/u/lsterzinger)\
**Post date:** [March 23, 2021, 3:31pm UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793/1 "2021-03-23T15:31:12Z")

</div>

Hello,

edit: working example

```julia
using Plots
x = rand(10,10) / 1e6
contourf(x)

```

![example](https://global.discourse-cdn.com/julialang/original/3X/9/0/906c7f60b78865fc2039b73f0d0a76f5e37b0be8.png)

I don’t like how the colorbar’s labels are cut off by the plot edge. Is there a way to tell the plotting package to use scientific notation for the colorbar contour labels? I know there’s `xformatter/yformatter=:scientific` but I can’t find anything for the colorbar.

---

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [March 23, 2021, 5:42pm UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793/2 "2021-03-23T17:42:56Z")

</div>

The best that I got was using Plotly and some margin adjustments:

```julia
using Plots; plotly()
x = rand(10,10) / 1e6
contourf(x,
    left_margin = 5Plots.mm,
    right_margin = 10Plots.mm,
    top_margin = 5Plots.mm,
    bottom_margin = 5Plots.mm,
    colorbar_title = "Text Color Bar",
)

```

![Captura de tela de 2021-03-23 14-41-54](https://global.discourse-cdn.com/julialang/original/3X/d/d/dd99375f34635bfe64a5e0b99d6b0af4b0f5fed9.png)

---

<div class="post-metadata">

**Author:** ![lsterzinger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lsterzinger/32/23208_2.png) [@lsterzinger](https://discourse.julialang.org/u/lsterzinger)\
**Post date:** [March 23, 2021, 5:52pm UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793/3 "2021-03-23T17:52:38Z")

</div>

I don’t mind using plotly, but I really don’t like the nano/mico suffix on the colorbar and would still prefer scientific notation. Do you know if this is possible with Plotly?

---

<div class="post-metadata">

**Author:** ![lsterzinger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lsterzinger/32/23208_2.png) [@lsterzinger](https://discourse.julialang.org/u/lsterzinger)\
**Post date:** [March 23, 2021, 8:45pm UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793/4 "2021-03-23T20:45:36Z")

</div>

I guess what I’m looking for is something similar to the output of similar code in Python/matplotlib.  
 ![Figure_1](https://global.discourse-cdn.com/julialang/original/3X/9/7/97fd8061f8786cf0bc66192c2d7de39d3dcd7b70.png)

However, when I plot via the `pyplot()` backend of Plots.jl, this does not happen  
 ![Figure_2](https://global.discourse-cdn.com/julialang/original/3X/1/3/13817e80106234218f3084c4e062eda24e6fe665.png)

_edit:new user restrictions removed so I embedded the second image instead of providing it via link_

---

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [March 23, 2021, 9:08pm UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793/5 "2021-03-23T21:08:12Z")

</div>

The `Plots.jl` library is altering the Matplotlib theme and I don’t know where to look to remove this customization.

With `PyPlot` I got your result.

```julia
using PyPlot
x = rand(10,10) / 1e6
contourf(x)
colorbar()
gcf()

```

---

<div class="post-metadata">

**Author:** ![lsterzinger](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lsterzinger/32/23208_2.png) [@lsterzinger](https://discourse.julialang.org/u/lsterzinger)\
**Post date:** [March 23, 2021, 9:25pm UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793/6 "2021-03-23T21:25:38Z")

</div>

Hmm yeah I get the same thing when calling `PyPlot` directly instead of using `Plots.jl`, so it seems like the Plots.jl wrapper is customizing the plot environment in some way. If I figure out anything further I’ll be sure to update here.

Thanks!

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [March 24, 2021, 5:30pm UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793/7 "2021-03-24T17:30:52Z")

</div>

I asked in the Slack I learned that @isentropic (sorry if not the same isentropic) is working on this kind of enhancements here:  
[https://github.com/JuliaPlots/Plots.jl/pull/3346](https://github.com/JuliaPlots/Plots.jl/pull/3346)  
That PR has had a lot of activity recently so it seems like something good could come out soon!

---

<div class="post-metadata">

**Author:** ![isentropic](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/isentropic/32/11894_2.png) [@isentropic](https://discourse.julialang.org/u/isentropic)\
**Post date:** [April 1, 2021, 6:05am UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793/8 "2021-04-01T06:05:48Z")

</div>

This has been merged and already live in Plots#master with pyplot backend

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [April 1, 2021, 9:31pm UTC](https://discourse.julialang.org/t/scientific-notation-in-plots-jl-colorbar/57793/9 "2021-04-01T21:31:30Z")

</div>

@lsterzinger

Perhaps it’s too late to give another solution, but I post it here as an alternative. With PlotlyJS.jl you can customize better the plot appearance. In your case setting colorbar\_exponentformat =“power” or colorbar\_exponentformat=“e” you get what you’d like to be displayed as ticklabels:

```julia
using PlotlyJS
z = rand(10,10) / 1e6
trace=contour(z=z', colorbar_thickness=23, 
              colorbar_exponentformat="power")
pl=plot(trace, Layout(width=400, height=350))
display(pl)

```

![expf-power](https://global.discourse-cdn.com/julialang/original/3X/4/a/4ab693d8bea9fb409ae2b019bdd9e3fda9b742ff.png)

respectively:  
 ![expf-e](https://global.discourse-cdn.com/julialang/original/3X/5/6/5677f5861cb75e7a30c6aca7256d92f4ccf73b72.png)

Note that the transpose, z’, is necessary instead z, because of the major order used by plotly.js to serialize the arrays.
