set categoryarray=None for that axis when matches=None
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 18.8k
- Fork
- 2.8k
- Merge trung bình
- 16 giờ 26 phút
- Pull request đã merge (30 ngày)
- 21
Mô tả
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'})
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với bản tái hiện Plotly Express có các hàng được phân vùng được cung cấp, rồi kiểm tra các đối tượng layout xaxis, xaxis2 và xaxis3 được tạo ra trước và sau khi đặt matches=None. Xác minh rằng việc xóa categoryarray và categoryorder sẽ loại bỏ các giá trị danh mục trên toàn bộ facet, đồng thời giữ nguyên thiết lập category_orders tường minh, và xác nhận layout trục thu được bằng các ví dụ đã cho.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100