我正在试着找出两者之间的区别:

  • fig.update_layout({'yaxis': dict(matches=None)})
  • fig.update_yaxes(matches=None)

我以为它们是一样的,但是fig.update_layout({'yaxis': dict(matches=None)})个不会像预期的那样改变yAxis.

以下是示例代码:

import plotly.express as px
import plotly
print("plotly version: " , plotly.__version__)
# Sample data
data = {
    'Variable': ['A', 'A', 'B', 'B', 'C', 'C'],
    'Value': [1, 2, 3, 4, 5, 6]
}

# Create box plot
fig = px.box(data, y='Value', facet_row='Variable')
fig.update_layout(height=400, width =400)
fig.update_layout({'yaxis': dict(matches=None)})
fig.show()

fig.update_yaxes(matches=None)
fig.show()

输出:

enter image description here

推荐答案

之所以会发生这种情况,是因为当您使用facet_row参数时,会生成多个yaxe.您可以单独设置它们,如下所示:

fig.update_layout({'yaxis': dict(matches=None)})
fig.update_layout({'yaxis2': dict(matches=None)})
fig.update_layout({'yaxis3': dict(matches=None)})

或者以一种更具活力的方式:

## retrieve all yaxis names: ['yaxis', 'yaxis2', 'yaxis3']
yaxis_names = ['yaxis'] + [axis_name for axis_name in fig.layout._subplotid_props if 'yaxis' in axis_name]
yaxis_layout_dict = {yaxis_name:dict(matches=None) for yaxis_name in yaxis_names}
fig.update_layout(yaxis_layout_dict)

Python相关问答推荐

两极按组颠倒顺序

为什么我的代码会进入无限循环?

使用decorator 重复超载

如何才能将每个组比上一组增加N %?

使用Python C API重新启动Python解释器

使用Beautiful Soup获取第二个srcset属性

计算相同形状的两个张量的SSE损失

Pandas 填充条件是另一列

删除最后一个pip安装的包

输出中带有南的亚麻神经网络

加速Python循环

Python中绕y轴曲线的旋转

移动条情节旁边的半小提琴情节在海运

无法在Docker内部运行Python的Matlab SDK模块,但本地没有问题

当递归函数的返回值未绑定到变量时,非局部变量不更新:

用砂箱开发Web统计分析

为什么numpy. vectorize调用vectorized函数的次数比vector中的元素要多?

无论输入分辨率如何,稳定扩散管道始终输出512 * 512张图像

如何在Pyplot表中舍入值

为什么调用函数的值和次数不同,递归在代码中是如何工作的?