plotly(v4.5.0)是否无法将原始字符串处理到LaTeX中以用于3D图形轴标签?
要进行测试,我正在Jupyter笔记本中运行以下代码。我特意尝试了几种不同的字符串格式,以试验API如何处理它们。原始字符串为title
生成LaTeX。但是我找不到scene
元素的轴或刻度标签。
import numpy as np
import plotly.graph_objs as go
# define time and space data
x = np.linspace(-10, 10, 400)
t = np.linspace(0, 4*np.pi, 200)
xx, tt = np.meshgrid(x, t)
f1 = 1/np.cosh(xx + 3) * np.exp(1j*2.3*tt)
# visualize
fig = go.Figure(go.Surface(z=np.real(f1), x=xx, y=tt))
fig.update_layout(title=r'$f_1(t)$',
autosize=False, width=500, height=500,
margin=dict(l=20, r=20, b=20, t=40),
scene=dict(xaxis=dict(title=r'x'),
yaxis=dict(title=r'$t$')))
fig.update_layout(scene=dict(xaxis=dict(nticks=3),
yaxis=dict(ticktext=["0",r"\pi",r"$2\pi$","3\pi","4\pi"],
tickvals=np.linspace(0,4*np.pi,5))))
fig.show()
答案 0 :(得分:-1)
从上面的描述中不清楚您要实现的目标,但是我正确理解的是您正在尝试更改表面图中的轴标签。这是您可以轻松实现的方式。
import numpy as np
import plotly.graph_objs as go
# define time and space data
x = np.linspace(-10, 10, 400)
t = np.linspace(0, 4*np.pi, 200)
xx, tt = np.meshgrid(x, t)
f1 = 1/np.cosh(xx + 3) * np.exp(1j*2.3*tt)
# visualize
fig = go.Figure(go.Surface(z=np.real(f1), x=xx, y=tt))
fig.update_layout(title='Plot Title',autosize=True,
width=900, height=900,
margin=dict(l=65, r=50, b=65, t=90))
fig.update_layout(scene = dict(
xaxis_title='X-axis Title',
yaxis_title='X-axis Title',
zaxis_title='X-axis Title'))
fig.show()
您还可以将等高线添加到曲面图:
import numpy as np
import plotly.graph_objs as go
# define time and space data
x = np.linspace(-10, 10, 400)
t = np.linspace(0, 4*np.pi, 200)
xx, tt = np.meshgrid(x, t)
f1 = 1/np.cosh(xx + 3) * np.exp(1j*2.3*tt)
# visualize
fig = go.Figure(go.Surface(z=np.real(f1), x=xx, y=tt))
fig.update_traces(contours_z=dict(show=True, usecolormap=True,
highlightcolor="limegreen", project_z=True))
fig.update_layout(title='Plot Title',autosize=True,
width=900, height=900,
margin=dict(l=65, r=50, b=65, t=90))
fig.update_layout(scene = dict(
xaxis_title='X-axis Title',
yaxis_title='Y-axis Title',
zaxis_title='Z-axis Title'))
fig.show()