holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.66k stars 396 forks source link

`hv.Bars` with more than one `kdim` randomly generates incorrect x-ticks in some cases (matplotlib backend) #6231

Closed sztal closed 1 month ago

sztal commented 1 month ago

As in the title

ALL software version info

(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc)

Description of expected behavior and the observed behavior

hv.Bars should display x-tick values correctly in all cases instead of making some random errors from time to time in a way which is completely unpredictable.

Complete, minimal, self-contained example code that reproduces the issue

import json
import pandas as pd
import holoviews as hv

hv.extension("matplotlib", logo=False)

json1 = '{"Pet":{"0":"Cat","1":"Cat","2":"Dog","3":"Dog","4":"Hamster","5":"Hamster","6":"Rabbit","7":"Rabbit"},"Gender":{"0":"Female","1":"Male","2":"Female","3":"Male","4":"Female","5":"Male","6":"Female","7":"Male"},"Count":{"0":26,"1":21,"2":36,"3":24,"4":27,"5":34,"6":39,"7":39}}'

json2 = '{"community":{"0":"Concerned","1":"Concerned","2":"Concerned","3":"Informants","4":"Informants"},"stance":{"0":"Dystopia","1":"Pragmatic","2":"Protect","3":"Dystopia","4":"Pragmatic"},"len":{"0":25,"1":41,"2":30,"3":1,"4":56}}'

df1 = pd.DataFrame(json.loads(json1))
df2 = pd.DataFrame(json.loads(json2))

For df1 it works.

hv.Bars(df1, kdims=["Pet", "Gender"])

But for df2 it does not work correctly for some mysterious reasons. Note that the lower values for x-ticks are incorrect (both groups are labelled as "Pragmatic" which is a value of stance variable not community) and display one of the levels of stance variable instead of displaying values of community column (`"Concerned" and "Informants").

hv.Bars(df2, kdims=["community", "stance"])

Please explain to me what is going on here, because it is extremely confusing. I really want to love holoviews because it has a lot of killer features, but sometimes it behaves in so cryptic unpredicable ways that makes it really painful to work with it.

Stack traceback and/or browser JavaScript console output

Screenshots or screencasts of the bug in action

hoxbro commented 1 month ago

If I understand you correctly, this is fixed in https://github.com/holoviz/holoviews/pull/6145 (not yet merged):

 Screenshot 2024-05-14 14 09 18

Current behavior:  Screenshot 2024-05-14 14 10 01

sztal commented 1 month ago

Great, thanks, I hope this will solve the issue. However, I still do not understand what makes any of the axes continuous? The two grouping variables are clearly discrete.

hoxbro commented 1 month ago

The bug was discovered and fixed in the PR. So, it is not directly related to the title.

See https://github.com/holoviz/holoviews/pull/6145/files#r1589356958