omartinsky / QuantAndFinancial

This repository contains supporting examples which are referenced from posts published on www.quantandfinancial.com
125 stars 127 forks source link

Error in display_frontier(result, label=None, color='black'): #2

Closed sabirjana closed 4 years ago

sabirjana commented 4 years ago

Hi, Thanks for the great work!! However, I am getting below error in display_frontier:

ValueError Traceback (most recent call last)

in 2 3 display_assets(names, R, C, color='blue') ----> 4 display_frontier(res1, color='blue') 5 xlabel('variance $\sigma$'), ylabel('mean $\mu$'), show() 6 display(pandas.DataFrame({'Weight': res1.W}, index=names).T) in display_frontier(result, label, color) 22 text(result.tan_var ** .5, result.tan_mean, 'tangent', verticalalignment='center', color=color) 23 scatter(result.tan_var ** .5, result.tan_mean, marker='o', color=color), grid(True) ---> 24 plot(result.front_var ** .5, result.front_mean, label=label, color=color), grid(True) # draw efficient frontier C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in plot(scalex, scaley, data, *args, **kwargs) 2787 return gca().plot( 2788 *args, scalex=scalex, scaley=scaley, **({"data": data} if data -> 2789 is not None else {}), **kwargs) 2790 2791 C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in plot(self, scalex, scaley, data, *args, **kwargs) 1664 """ 1665 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map) -> 1666 lines = [*self._get_lines(*args, data=data, **kwargs)] 1667 for line in lines: 1668 self.add_line(line) C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in __call__(self, *args, **kwargs) 223 this += args[0], 224 args = args[1:] --> 225 yield from self._plot_args(this, kwargs) 226 227 def get_next_color(self): C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs) 384 385 if len(tup) == 2: --> 386 x = _check_1d(tup[0]) 387 y = _check_1d(tup[-1]) 388 else: C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in _check_1d(x) 1400 else: 1401 try: -> 1402 x[:, None] 1403 return x 1404 except (IndexError, TypeError): C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\arrays\numpy_.py in __getitem__(self, item) 224 result = self._ndarray[item] 225 if not lib.is_scalar(item): --> 226 result = type(self)(result) 227 return result 228 C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\arrays\numpy_.py in __init__(self, values, copy) 132 133 if values.ndim != 1: --> 134 raise ValueError("PandasArray must be 1-dimensional.") 135 136 if copy: ValueError: PandasArray must be 1-dimensional.
sabirjana commented 4 years ago

I could able to resolve the error. Thanks