Cannot plot a column against itself
See original GitHub issueCode Sample, a copy-pastable example if possible
import pandas as pd
df = pd.DataFrame({'x': [1, 2], 'y': [2, 1]})
df.plot(x='x', y='x')
# A similar issue that should be tested once fixed
s1 = pd.Series(range(5), name="x")
s2 = pd.Series(range(10, 15), name="x") # The following would work with "y" instead
pd.concat([s1, s2], axis=1).plot.scatter(x=0, y=1)
Problem description
The code above produces a KeyError: ‘x’
Expected Output
I would expect the above code to produce a line plot that starts at (1, 1) and ends at (2, 2).
Output of pd.show_versions()
[paste the output of pd.show_versions()
here below this line]
INSTALLED VERSIONS
commit: None python: 3.6.5.final.0 python-bits: 64 OS: Linux OS-release: 4.15.0-29-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_CA.UTF-8 LOCALE: en_CA.UTF-8
pandas: 0.23.1 pytest: None pip: 10.0.1 setuptools: 39.2.0 Cython: 0.28.3 numpy: 1.14.3 scipy: 1.1.0 pyarrow: None xarray: None IPython: 6.4.0 sphinx: None patsy: 0.5.0 dateutil: 2.7.3 pytz: 2018.3 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: 2.2.2 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: 1.0.1 sqlalchemy: 1.2.7 pymysql: None psycopg2: 2.7.4 (dt dec pq3 ext lo64) jinja2: 2.10 s3fs: None fastparquet: None pandas_gbq: 0.4.1 pandas_datareader: None
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (2 by maintainers)
Top GitHub Comments
Yes, that output is exactly what I would expect. I figured it was something “simple” but hidden in the inner workings of
plot()
. Hopefully, your PR will make it into the next release. Thanks for tracking down a/the solution.Thank you for the reply. I have some questions for you.
In your “first change”, I don’t want to plot y vs x, I want to plot x vs x. So I don’t see how that accomplishes what I am looking for.
In your “second change”, I do not want to create a new dataframe, I already have valid dataframe and I am simply selecting the columns that I want to plot. There doesn’t appear anything in the documentation that would prevent passing the same column name to both the x and the y argument.
I understand that there is a work around (create a copy of the series I want to plot against itself) but it seems that the plot method should be able to handle the plotting without this step.