matplotlib.pyplot.errorbar: ValueError: List is not a valid value for color

I’m trying to plot some values and their errors, and to make sure each value is considered separate, I’d like to make them all different colors. I keep running into this error that says I can’t use my list for the color parameter, which I don’t understand because all the documentation and examples I’ve read using matplotlib say this is the way to do that.

This is the code I used:

colors=['red', 'orange', 'green', 'blue', 'purple']
ground_states_graph=list(ground_state.values())
ground_states_err_graph=list(ground_state_err.values())
plt.errorbar(tsep_maxs, ground_states_graph, ground_states_err_graph, fmt='.', color=colors)

I got the following error:

ValueError                                Traceback (most recent call last)
Cell In[74], line 4
      2 ground_states_graph=list(ground_state.values())
      3 ground_states_err_graph=list(ground_state_err.values())
----> 4 plt.errorbar(tsep_maxs, ground_states_graph, ground_states_err_graph, fmt='.', color=colors)
      5 plt.fill_between(tsep_maxs, [ground_state[8]-ground_state_err[8]]*len(tsep_maxs),[ground_state[8]+ground_state_err[8]]*len(tsep_maxs),
      6                 color='grey')

File ~anaconda3Libsite-packagesmatplotlibpyplot.py:3030, in errorbar(x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, data, **kwargs)
   3009 @_copy_docstring_and_deprecators(Axes.errorbar)
   3010 def errorbar(
   3011     x: float | ArrayLike,
   (...)
   3028     **kwargs,
   3029 ) -> ErrorbarContainer:
-> 3030     return gca().errorbar(
   3031         x,
   3032         y,
   3033         yerr=yerr,
   3034         xerr=xerr,
   3035         fmt=fmt,
   3036         ecolor=ecolor,
   3037         elinewidth=elinewidth,
   3038         capsize=capsize,
   3039         barsabove=barsabove,
   3040         lolims=lolims,
   3041         uplims=uplims,
   3042         xlolims=xlolims,
   3043         xuplims=xuplims,
   3044         errorevery=errorevery,
   3045         capthick=capthick,
   3046         **({"data": data} if data is not None else {}),
   3047         **kwargs,
   3048     )

File ~anaconda3Libsite-packagesmatplotlib__init__.py:1465, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
   1462 @functools.wraps(func)
   1463 def inner(ax, *args, data=None, **kwargs):
   1464     if data is None:
-> 1465         return func(ax, *map(sanitize_sequence, args), **kwargs)
   1467     bound = new_sig.bind(ax, *args, **kwargs)
   1468     auto_label = (bound.arguments.get(label_namer)
   1469                   or bound.kwargs.get(label_namer))

File ~anaconda3Libsite-packagesmatplotlibaxes_axes.py:3580, in Axes.errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
   3574 kwargs['label'] = '_nolegend_'
   3576 # Create the main line and determine overall kwargs for child artists.
   3577 # We avoid calling self.plot() directly, or self._get_lines(), because
   3578 # that would call self._process_unit_info again, and do other indirect
   3579 # data processing.
-> 3580 (data_line, base_style), = self._get_lines._plot_args(
   3581     self, (x, y) if fmt == '' else (x, y, fmt), kwargs, return_kwargs=True)
   3583 # Do this after creating `data_line` to avoid modifying `base_style`.
   3584 if barsabove:

File ~anaconda3Libsite-packagesmatplotlibaxes_base.py:537, in _process_plot_var_args._plot_args(self, axes, tup, kwargs, return_kwargs, ambiguous_fmt_datakey)
    532 result = (make_artist(axes, x[:, j % ncx], y[:, j % ncy], kw,
    533                       {**kwargs, 'label': label})
    534           for j, label in enumerate(labels))
    536 if return_kwargs:
--> 537     return list(result)
    538 else:
    539     return [l[0] for l in result]

File ~anaconda3Libsite-packagesmatplotlibaxes_base.py:532, in <genexpr>(.0)
    529 else:
    530     labels = [label] * n_datasets
--> 532 result = (make_artist(axes, x[:, j % ncx], y[:, j % ncy], kw,
    533                       {**kwargs, 'label': label})
    534           for j, label in enumerate(labels))
    536 if return_kwargs:
    537     return list(result)

File ~anaconda3Libsite-packagesmatplotlibaxes_base.py:346, in _process_plot_var_args._makeline(self, axes, x, y, kw, kwargs)
    344 default_dict = self._getdefaults(set(), kw)
    345 self._setdefaults(default_dict, kw)
--> 346 seg = mlines.Line2D(x, y, **kw)
    347 return seg, kw

File ~anaconda3Libsite-packagesmatplotliblines.py:376, in Line2D.__init__(self, xdata, ydata, linewidth, linestyle, color, gapcolor, marker, markersize, markeredgewidth, markeredgecolor, markerfacecolor, markerfacecoloralt, fillstyle, antialiased, dash_capstyle, solid_capstyle, dash_joinstyle, solid_joinstyle, pickradius, drawstyle, markevery, **kwargs)
    373 self.set_drawstyle(drawstyle)
    375 self._color = None
--> 376 self.set_color(color)
    377 if marker is None:
    378     marker = 'none'  # Default.

File ~anaconda3Libsite-packagesmatplotliblines.py:1061, in Line2D.set_color(self, color)
   1053 def set_color(self, color):
   1054     """
   1055     Set the color of the line.
   1056 
   (...)
   1059     color : color
   1060     """
-> 1061     mcolors._check_color_like(color=color)
   1062     self._color = color
   1063     self.stale = True

File ~anaconda3Libsite-packagesmatplotlibcolors.py:246, in _check_color_like(**kwargs)
    244 for k, v in kwargs.items():
    245     if not is_color_like(v):
--> 246         raise ValueError(f"{v!r} is not a valid value for {k}")

ValueError: ['red', 'orange', 'green', 'blue', 'purple'] is not a valid value for color

I can’t find anyone else with a similar error.

New contributor

Caitlin Kubina is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật