set categoryarray=None for that axis when matches=None
未关闭
还没有人认领这个 Issue。
feature
P3
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
Current behaviour
When a plot is created with facetted rows and xaxes matches is set to None, in the bottom plot the ticklabels for the values that are in other rows are still visible.
import plotly.express as px
import plotly
df = plotly.data.election()
fig = px.scatter(df, x= 'winner', y='total', facet_row="winner")
fig.for_each_xaxis(lambda x: x.update(showticklabels=True, matches=None))
fig.show()
- When a facetted figure is created, the items regarding xaxes of the resulting fig.layout look like this:
'xaxis': {'anchor': 'y',
'categoryarray': [Joly, Coderre, Bergeron],
'categoryorder': 'array',
'domain': [0.0, 0.98],
'title': {'text': 'winner'}},
'xaxis2': {'anchor': 'y2', 'domain': [0.0, 0.98], 'matches': 'x', 'showticklabels': False},
'xaxis3': {'anchor': 'y3', 'domain': [0.0, 0.98], 'matches': 'x', 'showticklabels': False},
xaxis2andxaxis3refer to the two top rows, while xaxis refers to the bottom one. The main difference between the two groups is that xaxis has some additional items/properties:'categoryarray': [Joly, Coderre, Bergeron], 'categoryorder': 'array', 'title': {'text': 'winner'}- When we apply
fig.for_each_xaxis(lambda x: x.update(showticklabels=True, matches=None)), the same part offig.layoutgets updated to:
'xaxis': {'anchor': 'y',
'categoryarray': [Joly, Coderre, Bergeron],
'categoryorder': 'array',
'domain': [0.0, 0.98],
'showticklabels': True,
'title': {'text': 'winner'}},
'xaxis2': {'anchor': 'y2', 'domain': [0.0, 0.98], 'showticklabels': True},
'xaxis3': {'anchor': 'y3', 'domain': [0.0, 0.98], 'showticklabels': True},
- The
categoryarrayandcategoryorderelements are still there (with the values for the three facets, not only the bottom one), so we need to remove them, which we can do with:
fig.for_each_xaxis(lambda x: x.update(categoryorder=None, categoryarray=None))
or
fig.update_xaxes(categoryarray=None, selector={'anchor':'y'})
- The updated part of the dict is:
'xaxis': {'anchor': 'y', 'domain': [0.0, 0.98], 'showticklabels': True, 'title': {'text': 'winner'}},
'xaxis2': {'anchor': 'y2', 'domain': [0.0, 0.98], 'showticklabels': True},
'xaxis3': {'anchor': 'y3', 'domain': [0.0, 0.98], 'showticklabels': True},
Desired behaviour
- When a plot is created with facetted rows and xaxes matches is set to None,
categoryordershould be set toNonefor those axes. - If the
categoryorderhas been specified on plot creation, that order is respected even after settingcategoryordertoNone. It would only be changed if we set a new value for that argument:
import plotly.express as px
df = px.data.tips()
df['weekend'] = df['day'].apply(lambda x: "weekend" if x in ["Sat", "Sun"] else "weekday")
fig = px.bar(df, x="day", y="total_bill", color="smoker", barmode="group", facet_row="weekend",
category_orders={
"weekend":["weekday", "weekend"],
"day": ["Thur", "Fri", "Sat", "Sun"],
"smoker": ["Yes", "No"],
"sex": ["Male", "Female"]
})
fig.for_each_xaxis(lambda x: x.update(showticklabels=True, matches=None))
fig.update_xaxes(categoryarray=None, selector={'anchor':'y'})
fig.show()
fig.update_xaxes(categoryarray=["Sun", "Sat"], selector={'anchor':'y'})
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从提供的 Plotly Express 分面行复现开始,检查在设置 matches=None 之前和之后生成的 xaxis、xaxis2 和 xaxis3 layout 对象。验证清除 categoryarray 和 categoryorder 会移除跨 facet 的类别值,同时保留显式的 category_orders 设置,并使用所示示例确认生成的轴布局。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100