我想将轴上的文本样式更改为斜体,即。刻度字体
下面是相关的脚本片段:
代码:
import plotly.graph_objs as go
# figure input
thing = ["apple","ball","cat"]
name = [1,2,3]
t = dict(family="Univers LT Std", size=14,color='black')
# figure setup
fig = go.Figure(data=[go.Scatter(x=name, y=thing, type='scatter')])
fig.update_layout(yaxis=dict(title="<i>Deviation from median (%)</i>",
titlefont=t, tickfont=t,gridcolor='rgba(255, 255, 255, 0.2)', showgrid=True))
fig.show()
plotly :
如何在不更改任何其他字体属性的情况下将轴上的文本 apple, ball, cat
的文本样式更改为斜体
最佳答案
Plotly 允许一些 HTML styling直接在轴标签的字符串输入上。并且您可以轻松更改thing = ["apple","ball","cat"]
至['<i>apple</i>', '<i>ball</i>', '<i>cat</i>']
使用列表理解 thing = ['<i>'+elem+'</i>' for elem in thing]
plotly :
代码:
import plotly.graph_objs as go
thing = ["apple","ball","cat"]
thing = ['<i>'+elem+'</i>' for elem in thing]
name = [1,2,3]
t = dict(family="Univers LT Std", size=14,color='black')
fig = go.Figure(data=[go.Scatter(x=name, y=thing, type='scatter')])
fig.update_layout(yaxis=dict(title="<i>Deviation from median (%)</i>",
titlefont=t, tickfont=t,gridcolor='rgba(255, 255, 255, 0.2)', showgrid=True))
fig.show()
关于python - Plotly:如何将刻度文本设置为斜体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58878364/