Hello ,
I am encounting an issue with the plot part of the exercise when running from my local computer. Getting ValueError when trying to plot data.Note that it's the same error for each of them. I will truly appreciate any help here.
Set figure size
plt.figure(figsize=(15, 7))
Plot the notional exposure data as per the strike prices
plt.plot(call_options_data['Strike'],
call_options_data['OI_notional_exposure'])
Set the title and labels and their sizes
plt.title('Notional Exposure as per Their Strike Prices', fontsize=16)
plt.xlabel('Strike Price ($)', fontsize=15)
plt.ylabel('Exposure ($)', fontsize=15)
plt.tick_params(axis='both', labelsize=15)
Show the graph
plt.show()
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[21], line 5 2 plt.figure(figsize=(15, 7)) 4 # Plot the notional exposure data as per the strike prices ----> 5 plt.plot(call_options_data['Strike'], 6 call_options_data['OI_notional_exposure']) 8 # Set the title and labels and their sizes 9 plt.title('Notional Exposure as per Their Strike Prices', fontsize=16) File D:\Anaconda\envs\quantra_py\lib\site-packages\matplotlib\pyplot.py:2840, in plot(scalex, scaley, data, *args, **kwargs) 2838 @_copy_docstring_and_deprecators(Axes.plot) 2839 def plot(*args, scalex=True, scaley=True, data=None, **kwargs): -> 2840 return gca().plot( 2841 *args, scalex=scalex, scaley=scaley, 2842 **({"data": data} if data is not None else {}), **kwargs) File D:\Anaconda\envs\quantra_py\lib\site-packages\matplotlib\axes\_axes.py:1743, in Axes.plot(self, scalex, scaley, data, *args, **kwargs) 1512 """ 1513 Plot y versus x as lines and/or markers. 1514 (...) 1740 (``'green'``) or hex strings (``'#008000'``). 1741 """ 1742 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D) -> 1743 lines = [*self._get_lines(*args, data=data, **kwargs)] 1744 for line in lines: 1745 self.add_line(line) File D:\Anaconda\envs\quantra_py\lib\site-packages\matplotlib\axes\_base.py:273, in _process_plot_var_args.__call__(self, data, *args, **kwargs) 271 this += args[0], 272 args = args[1:] --> 273 yield from self._plot_args(this, kwargs) File D:\Anaconda\envs\quantra_py\lib\site-packages\matplotlib\axes\_base.py:388, in _process_plot_var_args._plot_args(self, tup, kwargs) 385 kw[k] = v 387 if len(tup) == 2: --> 388 x = _check_1d(tup[0]) 389 y = _check_1d(tup[-1]) 390 else: File D:\Anaconda\envs\quantra_py\lib\site-packages\matplotlib\cbook\__init__.py:1318, in _check_1d(x) 1312 with warnings.catch_warnings(record=True) as w: 1313 warnings.filterwarnings( 1314 "always", 1315 category=Warning, 1316 message='Support for multi-dimensional indexing') -> 1318 ndim = x[:, None].ndim 1319 # we have definitely hit a pandas index or series object 1320 # cast to a numpy array. 1321 if len(w) > 0: File D:\Anaconda\envs\quantra_py\lib\site-packages\pandas\core\series.py:1072, in Series.__getitem__(self, key) 1069 key = np.asarray(key, dtype=bool) 1070 return self._get_rows_with_mask(key) -> 1072 return self._get_with(key) File D:\Anaconda\envs\quantra_py\lib\site-packages\pandas\core\series.py:1082, in Series._get_with(self, key) 1077 raise TypeError( 1078 "Indexing a Series with DataFrame is not " 1079 "supported, use the appropriate DataFrame column" 1080 ) 1081 elif isinstance(key, tuple): -> 1082 return self._get_values_tuple(key) 1084 elif not is_list_like(key): 1085 # e.g. scalars that aren't recognized by lib.is_scalar, GH#32684 1086 return self.loc[key] File D:\Anaconda\envs\quantra_py\lib\site-packages\pandas\core\series.py:1122, in Series._get_values_tuple(self, key) 1117 if com.any_none(*key): 1118 # mpl compat if we look up e.g. ser[:, np.newaxis]; 1119 # see tests.series.timeseries.test_mpl_compat_hack 1120 # the asarray is needed to avoid returning a 2D DatetimeArray 1121 result = np.asarray(self._values[key]) -> 1122 disallow_ndim_indexing(result) 1123 return result 1125 if not isinstance(self.index, MultiIndex): File D:\Anaconda\envs\quantra_py\lib\site-packages\pandas\core\indexers\utils.py:341, in disallow_ndim_indexing(result) 333 """ 334 Helper function to disallow multi-dimensional indexing on 1D Series/Index. 335 (...) 338 in GH#30588. 339 """ 340 if np.ndim(result) > 1: --> 341 raise ValueError( 342 "Multi-dimensional indexing (e.g. `obj[:, None]`) is no longer " 343 "supported. Convert to a numpy array before indexing instead." 344 ) ValueError: Multi-dimensional indexing (e.g. `obj[:, None]`) is no longer supported. Convert to a numpy array before indexing instead.