1

I'm currently using seaborn to display two time series plots side by side. Each plot contains multiple time series and often the names of the series are the same between plots. I'd like to share the legend so that a time series named A on the left side is the same color as the time series named A on the right side.

Here's what I'm doing right now.

fig, axs = plt.subplots(ncols=2, figsize=(40, 15))

for dummy_val in range(2):
    ts = counts[counts['dummy_category'] == dummy_val]

    sns.tsplot(ts, time='day', unit='Dummy', condition='ts_name',
               value='count', ax=axs[dummy_val])

plt.show()
Luke
  • 6,699
  • 13
  • 50
  • 88
  • The `color=` parameter takes a dictionary mapping condition names to colors, you could use that. – mwaskom Jun 23 '17 at 20:16
  • There's a lot of different possible values, and I'd rather not have to enumerate colors for every single one. – Luke Jun 23 '17 at 21:02
  • Then you're out of luck, because matplotlib legends are a property of the axes, not the figure... – mwaskom Jun 23 '17 at 21:20
  • Seemed like there was a way to do it without seaborn: https://stackoverflow.com/questions/9834452/how-do-i-make-a-single-legend-for-many-subplots-with-matplotlib – Luke Jun 23 '17 at 22:51
  • 2
    @Luke you may want to provide a [mcve] of a plot for which you want to synchronize the legend entries, which makes it clear in how far a simple color dict is not an option. This might help people to provide you with a better solution. It might well be that the only thing missing is a smart way to create a colormapping. – ImportanceOfBeingErnest Jun 24 '17 at 07:39

0 Answers0