r - 使用 plotly 更改图表上的字体
问题描述
我正在用 plotly 绘制一些情节。所以一切都很好,但我对字体外观不满意。即在传说中我有一种字体,而对于 x 和 y 轴我有其他字体。那么任何人都可以帮助如何解决这个问题并使用与图例中的字体相同的字体吗?
x1 = lcBR$p
y1 = lcBR$L
x2 = lcAR$p
y2 = lcAR$L
fig <- plot_ly(x = ~ x1, y = ~ x1, name = '45º', type = 'scatter', mode = 'lines',
line = list(color = "black", width = 2))
fig <- fig %>% add_trace(x = ~ x1, y = ~ y1, name = 'Before reform', mode = 'lines',
line = list(color = "red", width = 2, dash = "solid"))
fig <- fig %>% add_trace(x ~ x2, y = ~ y2, name = 'After reform', mode = 'lines',
line = list(color = "blue", width = 2, dash = "dash"))
f <- list(
family = "Courier New, monospace",
size = 18,
color = "#7f7f7f")
x <- list(
title = "Share of Population",
titlefont = f)
y <- list(
title = "Share of income",
titlefont = f)
fig <- fig %>% layout(xaxis = x, yaxis = y)
fig
解决方案
您的代码看起来与 plotly 中的“普通”python 代码看起来有些不同;这是R代码吗?但是,您可以使用它fig.update_layout
来更新整个图形的布局并fig.update_xaxes
更改 x 轴的外观,包括文本;看看https://plotly.com/python/figure-labels/#global-and-local-font-specification
推荐阅读
- c# - C# - 如何初始化列表
在同一行 - centos - 如何保护库在 CentOS6 上不被卸载
- python - bash +如何验证数字(浮点数或整数)是否小于整数1
- ag-grid - 如何在编辑单元格内使用 AG-Grids agDateInput
- assembly - 是否可以使用 equ 计算小数表达式?
- c - 有没有办法在C中重复字符串中的字符?
- javascript - 浏览器标签通知
- javascript - 按日期排序数组并在重复项上增加数量
- dialog - Bot Framework SDK 4.11 DialogContextError:无法读取 undefinedTypeError 的属性“trackTrace”:无法读取未定义的属性“trackTrace”
- azure - 在 C# 中压缩 Azure Blob 文件被损坏