How to add a superscript or a subscript to an axis label to a 3D plot in plotly?
Asked Answered
F

2

15

How to add a superscript or a subscript to an axis label to a 3D plot in plotly?

I tried to use bquote, but it did not work. Googling did not bring much on the matter either.

Scavenged code:

library(plotly)
set.seed(123)

n <- 100
theta <- runif(n, 0, 2*pi)
u <- runif(n, -1, 1)


base<-'B1'
compare<-'A1'
plot (1, 1, main = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n'  ~.(compare)~ 'minus'~.(base)))


p <- plot_ly(x = ~sqrt(1 - u^2) * cos(theta), y = ~sqrt(1 - u^2) * sin(theta), z = ~u) %>%
  layout(
    title = "Layout options in a 3d scatter plot",
    scene = list(
      xaxis = list(title = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n'  ~.(compare)~ 'minus'~.(base))),
      yaxis = list(title = "Sin"),
      zaxis = list(title = "Z")
    ))
p

Thank you for your time!

Ferbam answered 24/7, 2017 at 13:52 Comment(0)
E
24

With HTML tags, for example:

yaxis = list(title = "Sin<sup>super</sup>")

More info here. Hope this helps!

enter image description here

Exanimate answered 24/7, 2017 at 14:16 Comment(2)
@Florian, how should I view this object? When I include a subscript in an axis label as you show above, the axis label disapears (when the plotly graph is viewed in both R Viewer and my web browser). Thanks.Hochstetler
Difficult to solve with such little information.Could you open a new question on SO with a reproducible example?Exanimate
Y
0

This also works for axis tick labels

tickvals=np.arange(1, 11)
fig.update_yaxes(range=[1, -0.5],
                 tickvals=tickvals,
                 ticktext= [f"10<sup>-{x}</sup>" for x in tickvals])

enter image description here

Yeah answered 13/6, 2024 at 8:51 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.