答读者问:奇奇怪怪的Python问题,Poltly中y轴文字位置控制

01写在前面

大家好,我是 阳哥 。

前几天,我再次分享了 《Plotly Express 可视化指南》这个内容。

有同学问了一个问题,这个问题有点冷门,但也有特定的用处,姑且称之为“奇奇怪怪”的问题吧。

cb1c4de6b36e0cd3ff610f38d366e329.png

我再进一步阐述下这个问题要表达的意思:如下面图片中,y轴的刻度标签文字是靠右对齐的,如何设置为靠左对齐?

cd1606de3d2216af0c9126003b81b95e.png

02初步实践

对于这个问题,我刚开始觉得 Plotly 应该提供了标准的参数来控制位置分布。

于是回复这位同学:“标题通过 plotly 来控制的”。幸亏这位同学进一步提问,我才开始自己去测验。

但实际上,我自己去实践了下,发现好像不行。

实践的途径如下:

plotly 本身是提供了 ticklabelposition 这个参数的。大家可以通过下面的链接了解更多的情况:

https://plotly.com/python/reference/layout/yaxis/#layout-yaxis

ticklabelposition 参数只能从以下值中进行选择:

Type: enumerated , one of ( "outside" | "inside" | "outside top" | "inside top" | "outside left" | "inside left" | "outside right" | "inside right" | "outside bottom" | "inside bottom" )

ticklabelposition 这个参数中,有一段说明文字,如下:

Determines where tick labels are drawn with respect to the axis Please note that top or bottom has no effect on x axes or when ticklabelmode is set to "period". Similarly left or right has no effect on y axes or when ticklabelmode is set to "period". Has no effect on "multicategory" axes or when tickson is set to "boundaries". When used on axes linked by matches or scaleanchor, no extra padding for inside labels would be added by autorange, so that the scales could match.

Similarly left or right has no effect on y axes or when ticklabelmode is set to "period".

这段话说明 设置 对于y轴中的 ticklabelposition 这个参数是没有效果的。

既然 plotly 中没有标准参数来控制,那咱们就只有想其他办法了。

03解决方案

在介绍解决办法之前,还是先描述下项

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值