Skip to content

Setting xticks on bar plot fails #1066

@mosc9575

Description

@mosc9575

Description

I found this nice example on how to set xticks, but this is not working if I set the kind to "bar".

The code

import numpy as np
import pandas as pd
import hvplot.pandas

nb_days = 30
index = pd.date_range(start='2021-01-01', periods=nb_days, freq='1D')
(pd.DataFrame(data={'x': np.random.randn(nb_days)}, index=range(nb_days))
     .hvplot()
     .opts(xticks=[(i,x.strftime('%Y-%m-%d')) for i,x in enumerate(index)], xrotation=90))

creates this nice figure.

grafik

Trying to activate a bar plot

import numpy as np
import pandas as pd
import hvplot.pandas

nb_days = 30
index = pd.date_range(start='2021-01-01', periods=nb_days, freq='1D')
(pd.DataFrame(data={'x': np.random.randn(nb_days)}, index=range(nb_days))
     .hvplot(kind="bar")
     .opts(xticks=[(i,x.strftime('%Y-%m-%d')) for i,x in enumerate(index)], xrotation=90))

is not working. In the browser console this message is printed.

171:444 Uncaught (in promise) TypeError: Cannot create property 'visuals' on number '0'
    at set visuals [as visuals] (eval at evalInContext (index.js:12:12), <anonymous>:444:7621)
    at u._oriented_labels_extent (eval at evalInContext (index.js:12:12), <anonymous>:452:6649)
    at u._tick_label_extents (eval at evalInContext (index.js:12:12), <anonymous>:464:1068)
    at get extents [as extents] (eval at evalInContext (index.js:12:12), <anonymous>:452:6396)
    at u.get_size (eval at evalInContext (index.js:12:12), <anonymous>:452:1182)
    at m.eval [as get_size] (eval at evalInContext (index.js:12:12), <anonymous>:452:1007)
    at m._content_size (eval at evalInContext (index.js:12:12), <anonymous>:447:1974)
    at m._measure (eval at evalInContext (index.js:12:12), <anonymous>:449:3824)
    at m.measure (eval at evalInContext (index.js:12:12), <anonymous>:449:2126)
    at a._measure (eval at evalInContext (index.js:12:12), <anonymous>:540:752)

This could be a duplicate of issue 975.

ALL software version info Python version : 3.9.10 | packaged by conda-forge | (main, Feb 1 2022, 21:24:11) IPython version : 8.4.0 Tornado version : 6.1 Bokeh version : 2.4.3 holoviews version : 1.15.0 hvplot version : 0.8.3 BokehJS static path : /opt/conda/envs/aiva-env/lib/python3.9/site-packages/bokeh/server/static node.js version : v17.4.0 npm version : 8.3.1 Operating system : Linux-4.19.0-21-amd64-x86_64-with-glibc2.31

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions