I have a pandas DataFrame
that looks like this, and I'm using it to graph the life of a character over period of days. The days
column is really "days since birth." For this example, the character was born on May 26th, 2023.
days health months
0 0 30 May 23
1 1 30
2 2 20
3 3 20
4 4 10
5 5 10
6 6 10 Jun 23
7 7 10
8 8 10
9 9 0
This is the seaborn BarPlot
.
I have significantly simplified the number of days the character is alive for the sake of reproducibility, but in my normal code, the number of days is in the hundreds, possibly thousands.
Here is a graph of my normal case.
As you can see, this graph is much more overloaded with bars, which seems to be impacting performance pretty negatively, with only a few hundred days.
So my question is this: can I convert the BarPlot
to the seaborn equivalent of a histogram with the way my DataFrame
is set up?
The ideal would look something like the image below (ignore my bad graphic design job), The red lines are only to highlight each section of the histogram. I am not looking to add those red lines.
Note, I also need to be able to keep the month labels in the same place as they are above, since there could be a section of time where the character's health stays the same for multiple months.
My code is minimal for the chart, but the size of the DataFrame
seems to be causing the slow rendering time.
ax = sns.barplot(dataframe, x='days', y='health', color='blue')
ax.set_xticklabels(dataframe.months)
plt.xticks(rotation=45)
plt.show()
Here's a line for the example DataFrame
, for easy reproducibility:
df = pd.DataFrame({'days': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'health': [30, 30, 20, 20, 10, 10, 10, 10, 10, 0], 'months': ["May 23", " ", " ", " ", " ", " ", "Jun 23", " ", " ", " "]})
Thank you in advance.