0

These two commands work in my script:

ax.errorbar(rv_times, rv_rvs, rv_sigma, color = 'maroon', marker = 'o', fmt='o', zorder = -1, ms=5)
ax.scatter(df['rv_times'], df['rv_rvs'], color = df['rv_telescopes'].map(colors), marker = 'o', s=10, zorder = 1)

I would like to combine them, so I tried:

ax.errorbar(df['rv_times'], df['rv_rvs'], df['rv_sigma'], color = df['rv_telescopes'].map(colors), marker = 'o', ms=10, zorder = 1)

But it gave an error:

ValueError: RGBA sequence should have length 3 or 4

Why, please? What does this error mean? The desired result is a graph with markers that have a different colour base of strings in rv_telescopes. I do not care about colour of errorbars, but I need to have markers with errorbars in the legend, so I cannot combine two plots - scatter and errorbars.

Edit after advice

This is was color is equal to:

print(df['rv_telescopes'].map(colors))

0        tab:blue
1        tab:blue
2        tab:blue
3        tab:blue
4        tab:blue
5        tab:blue
6        tab:blue
7        tab:blue
8        tab:blue
9        tab:blue
10       tab:blue
11       tab:blue
12       tab:blue
13       tab:blue
14       tab:blue
15       tab:blue
16       tab:blue
17       tab:blue
18       tab:blue
19       tab:blue
20       tab:blue
21     tab:orange
22     tab:orange
23     tab:orange
24     tab:orange
          ...    
849       tab:red
850       tab:red
851       tab:red
852       tab:red
853       tab:red
854       tab:red
855       tab:red
856       tab:red
857       tab:red
858       tab:red
859       tab:red
860       tab:red
861       tab:red
862       tab:red
863       tab:red
864       tab:red

So, the first column of numbers is wrong?

Elena Greg
  • 1,061
  • 1
  • 11
  • 26
  • This may help: https://stackoverflow.com/questions/43099279/matplotlib-scatter-valueerror-rgba-sequence-should-have-length-3-or-4 – David Lee Jun 24 '21 at 07:36
  • The confusing error means that `ax.errorbar` works similar to `ax.plot` and only accepts one color for everything. Colors can come in a few forms, such as the names you are using, or red-green-blue triples or red-green-blue-alpha quadruplets. So, the function first "thinks" you want to provide red-green-blue values and then complains that there aren't 3 (or 4) values. Now, a workaround to get what want is to draw the errorbars for each color separately. – JohanC Jun 24 '21 at 10:20
  • According to [Error bars in different colors with matplotlib](https://stackoverflow.com/questions/47699542/error-bars-in-different-colors-with-matplotlib) you can just replace `ax.errorbar(..., color=...)` with `ax.errorbar(..., ecolor=...)` which does accept a list of colors. – JohanC Jun 24 '21 at 10:29
  • I am sorry, the question is not properly understandable. I am not interested in different colours of errorbars but in different colours of markers with errorbars. – Elena Greg Jun 24 '21 at 13:24

0 Answers0