How to select the value of several DataFrame columns on the same graph with Seaborn?
Below is not a working code. It correctly displays the schedule for one column only, and you want to display several columns as below for example.
import pandas as pd
Import Matplotlib.pyPlot AS PLT
Import Seaborn AS SNS
SNS.SET ()
C1 = [0.3, 0.5, 0, 0.9]
C2 = [0.7, 0, 0.1, 0]
DCT = {'C1': C1, 'C2': C2}
DF = PD.DataFrame (DCT)
Print (DF)
SNS.BarPlot (x = df.index.Values, Y = 'C1', DATA = DF)
# SNS.BarPlot (x = df.index.Values, Y = 'C2', Data = DF)
Plt.Show ()
Desired Graph
Answer 1, Authority 100%
Approximate option. Probably, you can still somehow beautiful, but not yet invented:
df1 = df.stack (). Reset_index (Level = 1)
df1.columns = ['C', 'Value']
SNS.BarPlot (x = df1.index.Values, Y = 'Value', Hue = 'C', Data = DF1)
Plt.Show ()
That is, you need to make such a DataFrame
so that you can use the hue
split columns on C1
and C2
. In DF1
, I got the following:
c value
0 C1 0.3.
0 C2 0.7.
1 C1 0.5.
1 C2 0.0.
2 C1 0.0.
2 C2 0.1.
3 C1 0.9.
3 C2 0.0.
Answer 2, Authority 100%
By the way, if seaborn
is not a prerequisite, then everything is simple:
df.plot (kind = 'bar');
# or df.plot.bar ();