Scientific Notation in Plots.jl colorbar

Hello,

edit: working example

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

example

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.

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

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

1 Like

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?

I guess what I’m looking for is something similar to the output of similar code in Python/matplotlib.
Figure_1

However, when I plot via the pyplot() backend of Plots.jl, this does not happen
Figure_2

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

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.

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

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!

I asked in the Slack I learned that @isentropic (sorry if not the same isentropic) is working on this kind of enhancements here:

That PR has had a lot of activity recently so it seems like something good could come out soon!

2 Likes

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

1 Like

@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:

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

respectively:
expf-e

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