0

I'm trying to do something like: dataframe.plot.scatter(x='C1', y=['C2','C3'])

I'm also trying to connect points next to each other on the x axis with a line; I tried '-o' as an optional argument but this didn't work.

Does anyone know how to do this properly? (I have looked at multiple other solutions, and they all say to do what I did above, which gives be the below error. C1, C2, and C3 all have length of 747.)

  File "/.../main1.py", line 40, in <module>
    vkCompFrame.plot.scatter(x='C1', y=['C2','C3'], marker="o")
  File "/Users/[name]/Library/Python/3.8/lib/python/site-packages/pandas/plotting/_core.py", line 1669, in scatter
    return self(kind="scatter", x=x, y=y, s=s, c=c, **kwargs)
  File "/Users/[name]/Library/Python/3.8/lib/python/site-packages/pandas/plotting/_core.py", line 917, in __call__
    return plot_backend.plot(data, x=x, y=y, kind=kind, **kwargs)
  File "/Users/[name]/Library/Python/3.8/lib/python/site-packages/pandas/plotting/_matplotlib/__init__.py", line 71, in plot
    plot_obj.generate()
  File "/Users/[name]/Library/Python/3.8/lib/python/site-packages/pandas/plotting/_matplotlib/core.py", line 329, in generate
    self._make_plot()
  File "/Users/[name]/Library/Python/3.8/lib/python/site-packages/pandas/plotting/_matplotlib/core.py", line 1114, in _make_plot
    scatter = ax.scatter(
  File "/Users/[name]/Library/Python/3.8/lib/python/site-packages/matplotlib/__init__.py", line 1412, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/Users/[name]/Library/Python/3.8/lib/python/site-packages/matplotlib/axes/_axes.py", line 4369, in scatter
    raise ValueError("x and y must be the same size")
ValueError: x and y must be the same size```
Benjy Strauss
  • 99
  • 1
  • 5
  • 2
    `dataframe.plot(x="C1", y=["C1","C2"], marker='o')` – Quang Hoang Apr 04 '23 at 20:02
  • And if the `x` values aren't sorted yet: `df.sort_values('C1').plot(x='C1', y=['C2', 'C3'], marker='o')` – tdy Apr 04 '23 at 20:31
  • Did you check Quang's and my comments? You're still calling a different command (do not use `scatter`, just `plot` itself with a circle marker). – tdy Apr 05 '23 at 23:15
  • You can copy-paste this for testing: `import pandas as pd; import numpy as np; pd.DataFrame({'C1': np.random.random(747), 'C2': np.random.random(747), 'C3': np.random.random(747)}).sort_values('C1').plot(x='C1', y=['C2', 'C3'], marker='o')` – tdy Apr 05 '23 at 23:16

0 Answers0