3

May I ask what is the equivalent of hue in Matplotlib? I have a line of seaborn code and would need to convert it into Matplotlib format. Each box corresponds to 1 ID at that time. How do i create a legend as well? The dataframe dataset_filtered has 3 columns: time_window (x axis), id and LagTime which is y axis.

sns.catplot(x='time_window', hue='ID', y='LagTime', data= dataset_filtered, kind="box",showfliers=False)Expected boxplot I need

This is what I have written so far but it is not working...

# Generate a color dictionary using RGB for each Id
colors = []
for num in range(len(unique_id)):
    num = num + 1 
    color = (1/num, 1/num, 1/num)
    colors.append(color)
color_dictionary = dict(zip(unique_id, colors))
plt.figure(figsize=(30,15))
for time_window in dataset_filtered.index.unique():
    dataset_plot = dataset_filtered.loc[time_window]
    box = dataset_plot.boxplot('LagTime',patch_artist=True,boxprops=dict(facecolor=color_dictionary['id']),medianprops=dict(color='black'),labels='id')
plt.xlim(-0.5,8)    
plt.xticks(np.arange(0.2,10,0.5),dataset_filtered.index.unique())
handles, labels = plt.gca().get_legend_handles_labels()
by_label = OrderedDict(zip(labels, handles))
plt.legend(by_label.values(), by_label.keys())
plt.xticklabels()
atjw94
  • 529
  • 1
  • 6
  • 22
  • Does this answer your question? [Scatter plots in Pandas/Pyplot: How to plot by category](https://stackoverflow.com/questions/21654635/scatter-plots-in-pandas-pyplot-how-to-plot-by-category) – Lucas Dec 15 '19 at 21:57

0 Answers0