plotly / plotly/plotly.py

set categoryarray=None for that axis when matches=None

Abierto
#4,365 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature P3
Lenguaje dominante
Python
Estrellas
18.8k
Forks
2.8k
Merge medio
16 h 26 min
PR fusionados (30 d)
21

Descripción

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()

image

  • 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},
  • xaxis2 and xaxis3 refer 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 of fig.layout gets 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 categoryarray and categoryorder elements 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, categoryorder should be set to None for those axes.
  • If the categoryorder has been specified on plot creation, that order is respected even after setting categoryorder to None. 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()

plot_20sep

fig.update_xaxes(categoryarray=["Sun", "Sat"], selector={'anchor':'y'})

plot_20sep_2

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la reproducción proporcionada de Plotly Express con filas facetadas e inspecciona los objetos de layout xaxis, xaxis2 y xaxis3 generados antes y después de establecer matches=None. Verifica que borrar categoryarray y categoryorder elimina los valores de categoría comunes a todas las facetas, preservando al mismo tiempo una configuración explícita de category_orders, y confirma el layout de los ejes resultante con los ejemplos mostrados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
data-visualization
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
42/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.