2

I have a layer with really small values and the classes in the legend do not look nice both for work in QGIS but also in the print layout.

QGIS layer properties window

Is it possible to somehow change the format of the numbers in the layer legend so instead numbers like:

0.000012345

I could get scientific notation:

1.2345e-5

or do I have to manually convert the numbers from the legend somewhere "outside" - maybe in some online tool like this and then paste it back in the legend as class label?

I googled and also looked in the QGIS documentation but did not find any solution.

3
  • I think this is essentially a duplicate of gis.stackexchange.com/questions/145004/… generalised to "how do I control the format of legend numbers". The python code in one of the answers, modified, could work to return scientific notation. I was surprised that expressions can't be used in the format box and I'm not sure if that's a requested feature... – Spacedman Jan 25 at 15:29
  • Using 3.16.1 I automatically get 1e-09 for e.g. 0.000000001 – MrXsquared Jan 25 at 15:31
  • Looks like a feature request from 7 years ago... github.com/qgis/QGIS/issues/16552 – Spacedman Jan 25 at 15:32
1

For now, I think it's not possible in the layer properties.

But you can do something with the legend item in your layout by adding an expression to the vector layer and each child symbol's label with an expression like this :

    array_to_string(
    array_foreach(
    --split with dash
    string_to_array( @symbol_label,'-'),
    to_real(
    --replace comma by point (useful for french like me)
    replace(@element,',','.'))),' - ')

Documentation :

https://docs.qgis.org/3.16/en/docs/user_manual/print_composer/composer_items/composer_legend.html#data-define-the-legend-labels

Example :

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.