JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.83k stars 354 forks source link

[BUG] Removing E-notation on colorbar ticks in pyplot backend disturbs polar heatmap layout #3158

Open fhagemann opened 3 years ago

fhagemann commented 3 years ago

When working with very small (e.g. 1e-100) or very big numbers (e.g. 1e100), polar heatmaps with the pyplot backend show a weird layout. This is probably due to the format of the colorbar tick labels. Since Plots v1.3.3 (#2722), the pyplot backend writes the tick labels with all decimal places which seems to mess up the layout of the polar plot.

Minimum working example for a polar heatmap with very small numbers (order 1e-100):

using Plots; pyplot()
θ = range(0, 2π, length = 100)
r = range(0, 100, length = 100)
heatmap(θ, r, 1e-100*randn(length(r), length(θ)), projection = :polar, size = (400,400))

Plots v1.3.2 and before: Plots_1 3 2

Plots v1.3.3 until Plots v1.7.1: Plots_1 3 3

With Plots v1.7.2 (#3088), the layout changed, but the plot is still layout is still not recovered. It is also interesting that the right ticks in the polar plot shows 180° rather than 0°.

Plots v1.7.2 and after: Plots_1 7 2

The gr backend displays the colorbar tick labels in the E-notation (1E-100), preventing very long numbers.

Is there a way of setting the formatting of the colorbar tick labels back to the E-notation from Plots v1.3.2 with a keyword argument or is it possible to implement a default value for which the pyplot backend switches back to the E-notation?

isentropic commented 3 years ago

Thanks for your thorough research, I think the current behavior --- avoiding exponential offsets, is better as it complies with other backends better. So I would normally suggest this solution

using Plots.PlotMeasures
θ = range(0, 2π, length = 100)
r = range(0, 100, length = 100)
heatmap(θ, r, 1e-100 .* randn(length(r), length(θ)), projection = :polar, size = (400,400),
    cbartitle=raw"$\times 10^{-100}$", right_margin = 100px)

image

But it is doing something I did not expect. Did something happen at https://github.com/JuliaPlots/Plots.jl/pull/3088? A better solution would be to calculate the color bar ticks within Plots (but this is something Plots does not do, am I right @daschw ?)

isentropic commented 3 years ago

At this point I can only suggest you to hack the underlying PyObject and adjust things there. You can access it

p1 = heatmap(θ, r, 1e-100*randn(length(r), length(θ)), projection = :polar, size = (400,400))
p1.o  # This is an pyobject that contains matplotlib content of the plot where you can tweak it if you know the matplotlib api
fhagemann commented 3 years ago

Thanks @isentropic for your reply, that will help!!

I was just a bit confused because gr converts the ticks to the E-notation GR