The exponent_format
parameter in the theme(...)
function can be used to configure the way "exponent notation" looks like on plot.
Available values:
'e'
for E notation, for example, 1.23e+3, which is the default format.'pow'
for superscript power notation.The "exponent format" is automatically applied to each value formatted in scientific notation, regardless whether the format is user-defined or chosen automatically based on the data. This format affects every part of a plot, including geoms, scales, labels, and tooltips.
Note:¶
Do NOT(!) use
exponent_format='pow'
if you are planning to export plot to a raster format (PNG,PDF).The
CairoSVG
library (which is under the hood of ourggsave()
function) does not handretspan
element properly end breaks superscript notation when transforming SVG to PNG/PDF.More details: https://github.com/Kozea/CairoSVG/issues/317
from lets_plot import *
import numpy as np
LetsPlot.setup_html()
exponent_format='pow'
for all plots in the notebook¶Each plot still can be cofigured individually: p + theme(exponent_format='e'))
# LetsPlot.set_theme(theme(exponent_format='pow'))
n = 10
data = {
'x': list(range(n)),
'y': [(i + 1 + 0.025 * i) * 10**(-5) for i in range(n)],
'c': [i * 10**(10) for i in range(n)]
}
p = ggplot(data, mapping=aes(x='x', y='y', fill='c')) + geom_bar(stat='identity')
pow_theme = theme(exponent_format='pow')
In this example "scientific notation" formatting for the guides is chosen automatically, basing on the data.
gggrid([p + ggtitle("E-notation (default)"),
p + pow_theme + ggtitle("Superscript Power")])
geom_text()
and geom_label()
¶By default, values in geom_text()
and geom_label()
are always shown in standard notation.
Thus by default, the 'pow'
in theme()
doesn't affect numbers in geom_text()
and geom_label()
(see the chart on the left) unless
you specify a scientific notation formatting explicitly via the label_format
parameter (see the chart on the right).
left = p + geom_label(aes(label='y'), alpha=0.8, fill='white')
right = p + geom_label(aes(label='y'), alpha=0.8, fill='white', label_format='.2~e')
gggrid([left, right]) + pow_theme