python 3.x - Plotting Pandas: Grouped line chart -
i have pandas dataframe in following format:
groups value 1 0 0 0 0 0 0 0.1 1 0.4 1 0.5 0 0.5 1 0.8 0 0.8 1 0.9 1 1 1 1 1 1 1 1 0 1 0 1
i want sorted line plot has value in y-axis, shown here:
anyway: want similar line each group in same plot well. (or 2 lines groups, differ in size)
can me out? reckon thats possible?
i use python 3.x pandas 0.16.2. i'd prefer using matplotlib or seaborn.
import pandas pd import numpy np import matplotlib.pyplot plt df = pd.read_csv('/home/jian/downloads/real_data.csv') # processing # ========================== fig, ax = plt.subplots() ax.set_ylim([0, 1.2]) count = 0 def func(group): group.sort('value', inplace=true) x = np.linspace(0, 1, len(group)) global ax, count if count > 0: ax.plot(x, group.value, label=group.groups.values[0]) count += 1 return group df.groupby('groups').apply(func) ax.legend(loc='best')
Comments
Post a Comment