Axis labels are not shown for all subplots when using plotly express, facets and string labels
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ả
Problem summary
Whenever I have the following combination:
- plotly express
- facet plots
- labels used for axis are strings
The first subplot shows the axis labels properly, but all following subplots don't show labels at all:

If the axis labels are numbers, there is no problem.
From a comment of the initial issue I opened I now know that fig.update_traces(bingroup='x2', row=1, col=2) can work around the issue, but that's not a permanent solution.
Reproducible example
I originally created these plots in Python (plotly 5.18.0) and then used the .to_json(pretty=True) method to obtain the Javascript for the codepens.
- Manually building up the figure using
graph_objectsandmake_subplotsI get the following working visualization: https://codepen.io/sl1970/pen/BaMvNbp - If I use the convenient
plotly.expresslibrary and thefacetargument I get this broken visualization (no axis labels on the right plot): https://codepen.io/sl1970/pen/jOdXPoa
Original Python code
If necessary, this is the original Python code I used
import pandas as pd
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
df = pd.DataFrame(
{
"age": { "0": "Adult", "1": "Adult", "2": "Adult", "3": "Adult", "4": "Adult", "5": "Kid", "6": "Kid", "7": "Kid", "8": "Kid", "9": "Kid", },
"favourite_food": { "0": "Pizza", "1": "Noodles", "2": "Pizza", "3": "Pizza", "4": "Pizza", "5": "Burger", "6": "Pancake", "7": "Noodles", "8": "Pizza", "9": "Pancake", },
"favourite_drink": { "0": "Beer", "1": "Tea", "2": "Beer", "3": "Wine", "4": "Coffee", "5": "Coffee", "6": "Water", "7": "Beer", "8": "Tea", "9": "Wine", },
"max_running_speed": { "0": 4.7362803248, "1": 16.7084927714, "2": 8.1135697835, "3": 1.0704264989, "4": 4.6330187561, "5": 6.331593807, "6": 16.5221040135, "7": 3.2256763127, "8": 4.3084468631, "9": 6.3677742299, },
"number_of_bicycles": { "0": 4, "1": 2, "2": 1, "3": 3, "4": 4, "5": 3, "6": 3, "7": 3, "8": 4, "9": 2, },
}
)
df.set_index("age", inplace=True)
working = make_subplots(rows=1, cols=2, subplot_titles=["Food", "Drink"])
working.add_trace( go.Histogram( histfunc="count", histnorm="percent", x=df.loc["Adult"].favourite_food, name="Adult", legendgroup="Adult", ), row=1, col=1, )
working.add_trace( go.Histogram( histfunc="count", histnorm="percent", x=df.loc["Kid"].favourite_food, name="Kid", legendgroup="Kid" ), row=1, col=1, )
working.add_trace( go.Histogram( histfunc="count", histnorm="percent", x=df.loc["Adult"].favourite_drink, name="Adult", legendgroup="Adult", ), row=1, col=2, )
working.add_trace( go.Histogram( histfunc="count", histnorm="percent", x=df.loc["Kid"].favourite_drink, name="Kid", legendgroup="Kid" ), row=1, col=2, )
working.show()
broken = px.histogram(
df,
x=["favourite_food", "favourite_drink"],
facet_col="variable",
color=df.index,
barmode="group",
histnorm="percent",
text_auto=".2r",
).update_xaxes(matches=None, showticklabels=True).update_yaxes(matches=None, showticklabels=True)
broken.show()
Related
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 cách xử lý histogram và facet của plotly.express được mô tả trong ví dụ Python có thể tái lập, sau đó so sánh figure được tạo ra với ví dụ make_subplots đang hoạt động và các CodePen được liên kết. Hoàn tất có nghĩa là các nhãn trục chuỗi phân loại được render trên mọi facet mà không cần workaround bingroup, với một regression test bao phủ trường hợp này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- pandas, 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
- 35/100