Cannot make charts work with my data

Help us help you! Writing your post to the following guidelines will help Bokeh Discourse reviewers understand your question, and increases the likelihood of a response.
What are you trying to do?

I am trying to take what I thought I learned and apply it to my own real world use cases.

What have you tried that did NOT work as expected? If you have also posted this question elsewhere (e.g. StackOverflow), please include a link to that post.

That would be too many to mention.

If this is a question about Bokeh code, please include a complete Minimal, Reproducible Example so that reviewers can test and see what you see.

# heatsimp7

def seven1():
    from bokeh.plotting import figure, show
    from datetime import datetime, timedelta

    meds = ['Afinitor']

    dates = [(datetime.now() + timedelta(day * 1)) for day in range(0, 7)]

    week = ['sun', 'mon', 'tues', 'wed', 'thu', 'fri', 'sat']
    compliance = ['nr', 'yes', 'no', 'nr', 'nr', 'yes', 'yes']

    colors = [
        "#0B486B", "#79BD9A", "#CFF09E",
        "#79BD9A", "#0B486B", "#79BD9A",
        "#CFF09E",
    ]

    p = figure(title="Afinitor Compliance", tools="hover", toolbar_location=None,
               x_range=week, y_range=meds, x_axis_type='datetime',)

    p.rect(dates, compliance, color=colors, width=1, height=1)
    # maybe compliance is an x, not a y?
    show(p)


seven1()

In some cases, a screenshot of your plot will also be helpful.

  1. x_range and y_range are both simple lists. y_range works as expected. x_range is giving me
    milliseconds. My code says nothing about milliseconds. Is that some kind of default in x_axis_type=‘datetime’?

  2. I copied the dates variable verbatim from an earlier example in the first steps tutorial.

  3. Neither the term ‘day’ nor the term ‘hour’ appear on this page about datetime properties:
    bokeh.core.properties — Bokeh 2.4.2 Documentation
    Neither of them are on the page about DatetimeAxis, either, but as a newby I can only post one link.

  4. There are no colors anywhere.

  5. There are no values anywhere.

  6. The hover is there, but there’s nothing to hover over.

  7. I actually wanted a multi line graph, one line for each medication. But I made it simple after
    running into these issues, which did not go away with my simplicity.

  8. Maybe I need a different tutorial? One that treats me like a 5th grader? Or even a
    Kindergartner? Suggestions? Explanations?

Hi @malikarumi ,

What’s your ideal output here? Are you trying for a heatmap? You mention a multiline, but the code uses rect, so I’m not sure.

1 Like

In the meantime, here’s a way to at least show your data with the rects.

from bokeh.plotting import figure, show
from bokeh.models import FactorRange, DatetimeTickFormatter
from datetime import datetime, timedelta

meds = ['Afinitor']

# changed the datetime.now() to be today at midnight, so that the blocks sit centered over their ticks
dates = [(datetime.combine(datetime.today(), datetime.min.time()) + timedelta(day * 1)) for day in range(0, 7)]
compliance = ['nr', 'yes', 'no', 'nr', 'nr', 'yes', 'yes']

colors = [
    "#0B486B", "#79BD9A", "#CFF09E",
    "#79BD9A", "#0B486B", "#79BD9A",
    "#CFF09E",
]

p = figure(title="Afinitor Compliance",
           tools="hover",
           toolbar_location=None,
           x_axis_type="datetime",
           y_range=FactorRange(factors=tuple(set(compliance))),
           width=700,
           height=200
           )
p.xaxis[0].formatter = DatetimeTickFormatter(days="%a")
p.rect(x=dates, y=compliance, width=timedelta(days=1), color=colors, height=1)

show(p)
1 Like