question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot plot a column against itself

See original GitHub issue

Code 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:open
  • Created 5 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
danielwlogancommented, Jul 28, 2018

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.

1reaction
danielwlogancommented, Jul 28, 2018

Thank you for the reply. I have some questions for you.

  1. 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.

  2. 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plotting dataframe columns using a for loop - Stack Overflow
i have the following data in a dataframe. I wrote a for loop so every column would be plotted against BOND, ANGEL and...
Read more >
pandas.DataFrame.query — pandas 1.5.2 documentation
Evaluate a string describing operations on DataFrame columns. Notes. The result of the evaluation of this expression is first passed to DataFrame.loc and...
Read more >
How to plot a Pandas Dataframe with Matplotlib?
Matplotlib is an amazing python library which can be used to plot pandas ... In situations, where data is to be interpreted depending...
Read more >
Pandas Plot: Deep Dive Into Plotting Directly With Pandas
Let's then look at the first few columns of the dataset: ... To plot a graph using pandas, you can call the .plot()...
Read more >
Pandas Line Plot | Python - Machine Learning Plus
You can create quick line plot on a pandas dataframe in python to understand the ... The last column has the corresponding dates...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found