由网友(清酒暖风)分享简介:在 Python 的 Plotly 中,我们有这个漂亮的多 y 轴示例:这是代码的 如何修复它以获得不重叠的图表? 解决方案 尝试调整 layout()margin 参数的 padding (pad) 值/代码>.我发现你的其他参数最好的是 pad = 49In Plotly for Python, we have t...![使用Pandas,Seaborn和Plotly绘制漂亮的图表](https://p.xsw88.cn/allimgs/daicuo/20230906/1553.png)
在 Python 的 Plotly 中,我们有这个漂亮的多 y 轴示例:这是代码的
如何修复它以获得不重叠的图表?
解决方案![使用Pandas,Seaborn和Plotly绘制漂亮的图表](https://p.xsw88.cn/allimgs/daicuo/20230906/1553.png)
尝试调整 layout()
margin
参数的 padding (pad
) 值/代码>.
我发现你的其他参数最好的是 pad = 49
In Plotly for Python, we have this beautiful multiple y-axis example: here is the link for the code.
I tried to do the same with Plotly in R using this code:
library(plotly)
x <- 1:4
y1 <- c(1,2,3,4)
y2 <- c(4,3,2,1)
y3 <- c(1,4,1,4)
y4 <- c(4,1,4,1)
test <- data.frame(x, y1, y2, y3, y4)
plot_ly(data = test, x = ~x, y = ~y1
,type = "scatter", mode = "lines", width = 800, color = I("red")
,name = "name01") %>%
add_trace(x = ~x, y = ~y2, yaxis = "y2", color = I("blue"), name = "name02") %>%
add_trace(x = ~x, y = ~y3, yaxis = "y3", color = I("purple"), name = "name03") %>%
add_trace(x = ~x, y = ~y4, yaxis = "y4", color = I("green"), name = "name04") %>%
layout(
yaxis = list(
showline = FALSE, side = "left"
,title = "Label 1"
,color = "red"
)
,yaxis2 = list(
showline = FALSE
,overlaying = "y"
,title = "Label 2", anchor = "free"
,color = "blue"
)
,yaxis3 = list(
showline = FALSE, side = "right", overlaying = "y"
,title = "Label 3"
,color = "purple"
)
,yaxis4 = list(
showline = FALSE, side = "right", overlaying = "y", position = 1
,title = "Label 4", anchor = "free"
,color = "green"
)
,xaxis = list(
showline = FALSE, zeroline = FALSE, dtick = 1, title = ""
)
,showlegend = FALSE
,margin = list(
pad = 30, b = 90, l = 150, r = 90
)
,legend = list(orientation = "h")
)
But I get these overlapping labels:
How can I fix it to get a non overlapping chart?
解决方案Try tuning the padding (pad
) value for margin
argument of layout()
.
Best I found for your other parameters is with pad = 49
相关推荐
最新文章