plotly / plotly/plotly.py

set categoryarray=None for that axis when matches=None

Aperta
#4,365 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature P3
Lingua principale
Python
Stelle
18.8k
Fork
2.8k
Merge medio
16h 26m
PR unite (30g)
21

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione fornita di Plotly Express con righe sfaccettate e ispeziona gli oggetti di layout xaxis, xaxis2 e xaxis3 generati prima e dopo aver impostato matches=None. Verifica che la cancellazione di categoryarray e categoryorder rimuova i valori di categoria comuni a tutte le facet, preservando al contempo un’impostazione esplicita di category_orders, e conferma il layout degli assi risultante con gli esempi mostrati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.