Having issues to render a grouped bar chart for Blood Pressure Values


Hi Guys, I’m having some issues when trying to render a bar chart with grouped bars that represent Blood Pressure values (systolic and diastolic). I’ve tried altair and plost and even though I get some data rendered in the charts. It looks quite bad and for some reason I’m unable to get them rendering as full bars, and Instead they just show up as small squares in the chart. I’m posting here the plost snippet I’ve used, the Altair one is different but produced the same results.

Steps to reproduce

My dataframe looks like this:

Date sys dias
2022/09/30 08:49:00 149 109
2022/09/30 17:19:00 139 97
2022/09/30 21:40:00 127 91
2022/10/01 09:00:00 144 106
2022/10/01 15:41:00 131 96
2022/10/02 09:10:00 140 104

Code snippet:

    value=['sys', 'dias'],

Expected behavior:

I’m expecting so get something like this, where the sys and dias values are displayed grouped by the date they were taken.


Actual behavior:

But Instead this is what I’m getting:

PS: The small text on top of the chart is the date values, the ones at the bottom are tagged as ‘dias’ and ‘sys’.

Debug info

  • Streamlit version:1.13.0
  • Python version: 3.10.8
  • OS version: Windows 11 64bits
  • Browser version: Firefox 106.0.5

Thank you in advance for any tips or hints!

Hello and thanks for the reply! Not sure who posted it since for some reason I see my name on the reply! and my original question is no longer visible. But I’ve tried your suggestion:

The ‘date’ key is actually correct in my real dataset, I made a mistake of putting it with capital D on my question here in the forums. I’ve tried your snippet but still the chart is getting rendered differently compared to your screen capture:

I’ve made a sample repo public in case you want to see the code, which is quite simple really. The piece rendering the chart in question is this:

new_bp_df = split_bp_values(sorted_df)
new_bp_df['date']= pd.to_datetime(new_bp_df['date'])
    value=['sys', 'dias'],

Sample Repo - Testing Branch

Really I have no idea why it is getting rendered like that and not like all the examples I’ve seen around the blogs and even on the streamlit and Plost documentation. Could actually be some other issue with the rest of the code, but I’m not sure. I appreciate any extra help on this.

Thank you a lot for your time!

I can’t speak plost, but doing it with altair is quite simple once you tidy the data.

import io

import altair as alt
import pandas as pd
import streamlitas st

text = """Date|sys|dias
2022/09/30 08:49:00|149|109
2022/09/30 17:19:00|139|97
2022/09/30 21:40:00|127|91
2022/10/01 09:00:00|144|106
2022/10/01 15:41:00|131|96
2022/10/02 09:10:00|140|104

df = pd.read_csv(io.StringIO(text), sep="|")
df.Date = pd.to_datetime(df.Date)

chart = (
    alt.Chart(df.melt("Date", var_name="measure", value_name="value"))
    .encode(x="measure", y="value", color="measure", column="Date")


1 Like

Hey @tzero86,

Thanks for posting! It looks like you passed 'date' instead of 'Date' – check out this example here which seems to give the result you’re looking for.

1 Like

Sorry @tzero86! I accidentally overwrote your original post with my reply. I’ve fixed it now. Apologies for the confusion.

1 Like

One other thing is that I noticed you passed “True” to the “group” param – pretty sure “group” is supposed to be the name of a column rather than a boolean

1 Like

Thank you both!! I found the issue, it had to do with the dataframe data types itself. The sys and dias values were not converted to numeric. Once I did the following the chart is showing up as expected now in both Plost and Altair:

All I had to do was this:

new_bp_df.sys = pd.to_numeric(new_bp_df.sys)
new_bp_df.dias = pd.to_numeric(new_bp_df.dias)

Thank you a lot again! Checking your samples pointed me in the right direction to start checking the actual dataframe types, since running your examples directly was working correctly. So the issue must have been somewhere else, and indeed it was. Thanks again for spending time helping this streamlit/pandas newbie!

1 Like

how to get rid of lables in x axis