0

I have this plot enter image description here

I want to put legend with color codes horizontally below the plot. Also it will be great if I can chose the color in both the plots and in the legend. Right now it is generated as

fix,axes=plt.subplots(nrows=5,ncols=4, figsize=(20,20))
plots=[]
for i in range(0,5):
    for j in range(0,4):
        x = list(bdf.groupby('condition').mean().   [bdf.columns[detection_idx]])
        y1 = list(df.groupby('condition').mean() [df.columns[aesthetic_idx]])
    plots.append(axes[i][j].scatter(x,y1, c = range(0, len(conditions))))
    s = list(scenes.values())[i*4+j]
    axes[i][j].title.set_text(s)
    axes[i][j].set_xlabel('Detection accuracy')
    axes[i][j].set_ylabel('Visual aesthetics')
    aesthetic_idx+=4
    detection_idx+=1
    plt.figlegend(tuple(plots), tuple(conditions), loc='lower left', bbox_to_anchor=(0.0, -0.1), ncol=len(conditions))
Rakib
  • 7,435
  • 7
  • 29
  • 45
  • You need to assign labels to each *dataset* individually to create a legend - see this [SO answer](https://stackoverflow.com/a/17412294/2823755). – wwii Sep 16 '17 at 16:56
  • [Matplolib gallery example](https://matplotlib.org/examples/lines_bars_and_markers/scatter_with_legend.html) – wwii Sep 16 '17 at 17:02
  • Seems the datasets for each subplot would need to be *categorized* the same. Maybe, see if you can add labels to each dataset for each subplot. Then come back with more specifc question(s). Also, a minimal example dataset would be nice, maybe start with a 1 row by 2 column subplot plot. - Please create an [mcve] so it is easier to work out the details. – wwii Sep 16 '17 at 17:09
  • From [this SO q&a](https://stackoverflow.com/q/9834452/2823755), looks like you are almost there. In addition to assigning labels to each dataset of each subplot, you should assign the color. If not already in a container you will have to accumulate the label *categories* for use in the legend. – wwii Sep 16 '17 at 17:25
  • 1
    Those are just too many different problems at once. If you break down the problem into several parts, you'll find a solution for each of them. I marked as duplicate of three different question for now. Of course if you have a problem with the implementation of one specific problem, feel free to edit the question or ask a new one. Don't forget to provide a [mcve] and clearly state how the desired plot should look like (i.e. here it is not even clear how many colors you need, what the legend should show and what problems you have putting the legend below the plot) – ImportanceOfBeingErnest Sep 16 '17 at 18:14
  • @ImportanceOfBeingErnest - how do you mark as duplicate to multiple questions? – wwii Sep 16 '17 at 18:24
  • @wwii That's a priviledge of gold badge holders. See this [meta post](https://meta.stackexchange.com/questions/291824/gold-tag-badge-holders-and-moderators-can-now-edit-duplicate-links). – ImportanceOfBeingErnest Sep 16 '17 at 18:38

0 Answers0