Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plt.scatter() errors
#1
Shocked 
Hey Py community,
I'm writing down Markowitz's efficient frontier with jupy using the 4 significant cryptos as stocks and verything is fine until the plt.plot() function comes up. I've used three different methods and none of them fits the expected return/expected volatility graph.
The first one is a np.linspace() function.
Error 1:

ValueError Traceback (most recent call last)
<ipython-input-506-825222cab96e> in <module>
5 plt.colorbar(label='sharpe ratio')
6 plt.scatter(expectedVolatility[maxIndex],expectedReturn[maxIndex],c='red')
----> 7 plt.scatter(volatility_opt,returns)
8 plt.show()

C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, data, **kwargs)
2888 verts=cbook.deprecation._deprecated_parameter,
2889 edgecolors=None, *, plotnonfinite=False, data=None, **kwargs):
-> 2890 __ret = gca().scatter(
2891 x, y, s=s, c=c, marker=marker, cmap=cmap, norm=norm,
2892 vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths,

C:\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
1445 def inner(ax, *args, data=None, **kwargs):
1446 if data is None:
-> 1447 return func(ax, *map(sanitize_sequence, args), **kwargs)
1448
1449 bound = new_sig.bind(ax, *args, **kwargs)

C:\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py in wrapper(*inner_args, **inner_kwargs)
409 else deprecation_addendum,
410 **kwargs)
--> 411 return func(*inner_args, **inner_kwargs)
412
413 return wrapper

C:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, **kwargs)
4439 y = np.ma.ravel(y)
4440 if x.size != y.size:
-> 4441 raise ValueError("x and y must be the same size")
4442
4443 if s is None:

ValueError: x and y must be the same size

The second one is a loop function
Error:
ValueError Traceback (most recent call last)
<ipython-input-107-189155ee8df1> in <module>
1 plt.figure(figsize=(20,6))
----> 2 plt.scatter(stds,returns)
3 plt.title('Efficient Frontier')
4 plt.xlabel('Portfolio std')
5 plt.ylabel('Porfolio returns')

C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, data, **kwargs)
2888 verts=cbook.deprecation._deprecated_parameter,
2889 edgecolors=None, *, plotnonfinite=False, data=None, **kwargs):
-> 2890 __ret = gca().scatter(
2891 x, y, s=s, c=c, marker=marker, cmap=cmap, norm=norm,
2892 vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths,

C:\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
1445 def inner(ax, *args, data=None, **kwargs):
1446 if data is None:
-> 1447 return func(ax, *map(sanitize_sequence, args), **kwargs)
1448
1449 bound = new_sig.bind(ax, *args, **kwargs)

C:\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py in wrapper(*inner_args, **inner_kwargs)
409 else deprecation_addendum,
410 **kwargs)
--> 411 return func(*inner_args, **inner_kwargs)
412
413 return wrapper

C:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, plotnonfinite, **kwargs)
4439 y = np.ma.ravel(y)
4440 if x.size != y.size:
-> 4441 raise ValueError("x and y must be the same size")
4442
4443 if s is None:

ValueError: x and y must be the same size

The third one doesn't show any error but the graph with go.Figure() from plotly is blank.

Probably it's a question of dimension but no clue what to do to improve the values' and let them be represented.

Thanks in advance.
Larz60+ write Oct-13-2022, 12:19 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to invert scatter plot axis Mark17 3 2,537 Sep-22-2021, 04:45 PM
Last Post: jefsummers
  Animated scatter plot maximan 0 1,652 Jan-18-2021, 03:53 PM
Last Post: maximan
  Group scatter plots Mekala 0 1,660 Jul-23-2020, 02:18 PM
Last Post: Mekala
  how to nest loop for 4*4 scatter plot kassamohammed 0 2,580 Jun-23-2020, 09:47 AM
Last Post: kassamohammed
  How to create Custom Buttons for 3D Scatter plots in Plotly? yourboyjoe 0 2,144 Jun-01-2020, 10:58 PM
Last Post: yourboyjoe
  colorbar for scatter shows no negatives values... gil 0 1,544 Apr-15-2020, 12:45 AM
Last Post: gil
  plotly.graph_objs - Scatter mode error sambanerjee 14 9,171 Mar-18-2020, 02:54 PM
Last Post: sambanerjee
  Scaled scatter modification yvrob 1 1,980 Nov-08-2019, 04:05 AM
Last Post: yvrob
  How to plot multiple scatter plots in seaborn vikola 2 6,513 Jul-14-2019, 10:30 AM
Last Post: vikola
  Create Animated Scatter plot in 3d using matplotlib in python barry76 0 3,901 Mar-29-2019, 12:13 PM
Last Post: barry76

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020