#๐Ÿ”’ Legend in matplot doesn't follow cmap

5 messages ยท Page 1 of 1 (latest)

shut spire
#

Hi, can someone help me why despite of setting cmap:
cmap = plt.colormaps.get_cmap('Set3')
and following snippet of the code:

for index, wn in enumerate(energylist):
    color = cmap(index / len(energylist))
    #single gauss function line plot
    if show_single_gauss:
        ax.plot(plt_range_x,gauss(intenslist[index], plt_range_x, wn, w),color=color,alpha=0.25) 
    #single gauss function filled plot

    legend_labels = [f'S{index+1}' for index in range(10)]

    if show_single_gauss_area:
        ax.fill_between(plt_range_x,gauss(intenslist[index], plt_range_x, wn, w),color=color,alpha=0.25)
        handles = [plt.Rectangle((0,0),1,1, color=color, alpha=0.25) for index in range(len(energylist))]
        ax.legend(handles, legend_labels, title='Single Gaussians', loc='center left', bbox_to_anchor=(1, 0.5))
        plt.subplots_adjust(right=0.85)  # Adjust plot layout to make room for legend

    # sum of gauss functions
    gauss_sum.append(gauss(intenslist[index], plt_range_x, wn, w))

the legend shows wrong?

placid thistleBOT
#

@shut spire

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#

Hey @shut spire!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
placid thistleBOT
#

@shut spire

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.