I want to create a bar chart that will contain bars for 2 columns of dataframe.
from matplotlib import pyplot as plt
import pandas as pd
s = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
p_s = [0.05, 0.15, 0.20, 0.30, 0.20, 0.10]
p_s_x = [0.06005163309361129, 0.4378503494734475,0.3489460783665687,0.1404287057633398,0.012362455732360653,0.00036077757067209113]
df_to_plot = pd.DataFrame(data={"P(S)": p_s,
"P(S|X)": p_s_x,
"S": s})
df_to_plot.plot.bar(y=['P(S)', 'P(S|X)'],
alpha=0.7,
color=['red', 'green'],
figsize=(8,5))
This dataframe is here.
And bar chart I generate by
df_to_plot.plot.bar(y=['P(S)', 'P(S|X)'],
alpha=0.7,
color=['red', 'green'],
figsize=(8,5));
that looks
I want to replace 0,1 ,..., 5 into 0.1, ..., 0.6 (it's my column S), so I set x.
df_to_plot.plot.bar(y=['P(S)', 'P(S|X)'],
x='S',
alpha=0.7,
color=['red', 'green'],
figsize=(8,5));
I don't have any idea how to correct it. I used to use parameters use_index, xticks but they couldn't work.
Could you look at it and advise? Thank you!
Edit Thanks to @Mr.T I made a few changes.
ax = df_to_plot.plot.bar(y=['P(S)', 'P(S|X)'],
alpha=0.7,
color=['red', 'green'],
figsize=(8,5));
ax.set_xticklabels(df_to_plot['S'])
ax = df_to_plot.plot.bar(y=['P(S)', 'P(S|X)'], alpha=0.7,...
which plots it against the index, thenax.set_xticklabels(df_to_plot["S"])
which substitutes the index labels. What is the outcome of this? Still weird behavior in any case.