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:
I’m expecting so get something like this, where the sys and dias values are displayed grouped by the date they were taken.
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’.
- 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)
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 altair as alt
import pandas as pd
import streamlitas st
text = """Date|sys|dias
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")
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.
Sorry @tzero86! I accidentally overwrote your original post with my reply. I’ve fixed it now. Apologies for the confusion.
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
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!
how to get rid of lables in x axis
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.