Fix plot column against itself
State: closed

My first ever open source PR, be gentle.

- [x] closes #22088
- [x] plotting tests passed 
(310 passed, 4 skipped, 2 xfailed, 4 xpassed, 39 warnings)
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
I ran this command and it returned nothing.

This allows for plotting of where `x` and `y` are the same column. I had to add the type check because otherwise it failed a check where `y` is a numpy array.


Labels:
name: Bug
name: Visualization
description: plotting

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22105?src=pr&el=h1) Report
> Merging [#22105](https://codecov.io/gh/pandas-dev/pandas/pull/22105?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/0b7a08b70444056f964bb636a74ac41ca0058d37?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `66.66%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/22105/graphs/tree.svg?width=650&height=150&src=pr&token=eZ4WkYLtcO)](https://codecov.io/gh/pandas-dev/pandas/pull/22105?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #22105      +/-   ##
==========================================
- Coverage   92.06%   92.06%   -0.01%     
==========================================
  Files         170      170              
  Lines       50705    50708       +3     
==========================================
+ Hits        46680    46682       +2     
- Misses       4025     4026       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.46% <66.66%> (-0.01%)` | :arrow_down: |
| #single | `42.3% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22105?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/22105/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `83.45% <66.66%> (-0.04%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22105?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22105?src=pr&el=footer). Last update [0b7a08b...6114111](https://codecov.io/gh/pandas-dev/pandas/pull/22105?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@RobMulla : Good start!  We definitely are going to need tests and a `whatsnew` entry for this.
I've updated this to account for if y is a list. Currently we set the index to x with `data = data.set_index(x)`. If x is also in y this causes a KeyError later on because x is no longer a column in the dataframe. With these changes we now check to see `if y is not none`, and if x is in y we set the drop to False `data = data.set_index(x, drop=False)`

With the current code:
```
import pandas as pd
print(pd.__version__)
df = pd.DataFrame({'x': [1, 2], 'y': [2, 1]})
df.plot(x='x', y='x', title='example 1')
df.plot(x='x', y=['x','y'], title='example 2')
df.plot(x='x', y=['x','y','z'], title='example 3')
df.plot(x='x', title='example 4')
```
*Example 1 returns: `KeyError: 'x'`*
*Example 2 and 3 return: `KeyError: "['x'] not in index"`*

With the changes all of the following work as expected:
```
import pandas as pd
df = pd.DataFrame({'x': [1, 2], 'y': [2, 1], 'z': [2, 2]})
df.plot(x='x', y='x', title='example 1')
df.plot(x='x', y=['x','y'], title='example 2')
df.plot(x='x', y=['x','y','z'], title='example 3')
df.plot(x='x', title='example 4') # This requires the `if y is not none` check
```
![image](https://user-images.githubusercontent.com/6800879/43437416-f25f1258-9456-11e8-984a-384f7f4a522e.png)
![image](https://user-images.githubusercontent.com/6800879/43437421-f8e541b0-9456-11e8-927e-5da1f2cce209.png)
![image](https://user-images.githubusercontent.com/6800879/43437423-fcd17118-9456-11e8-835b-da7a6646271c.png)
![image](https://user-images.githubusercontent.com/6800879/43437426-00ba70ae-9457-11e8-83bc-c47dd2c4c25d.png)
A few questions:

1. Does scatter and hexbin share this code? If not, they'll need a similar fix, so that `.scatter(x='x', y='y')` behaves similarly.
2. Does this change the behavior of `.plot(x='x')`, with no y specified? I suspect it does. I think that behavior is essentially `df.set_index('x').plot()`, which plots x against all the remaining columns. Since you no longer drop x from the columns, it'll be plotted again (I'm guessing).

Solving 2 sounds doable but messy.
First time contributing/reviewing! Is there any specific location guidance available? I see that all checks have failed, but have no idea where to start with this!
Welcome @Remnan13 ! I'd first ask @RobMulla if he cares to continue with this before taking over. If you click on the Details of any of the tests you can click through to the logs and see at the end what specifically is failing. 
How about it, @RobMulla? I'd like to help however I can if this is an ongoing bug in need of a fix.
@Remnan13 if you want I'd say make a new PR.  You can use this as a starting point if you want, or you can start fresh.

Addressing the issues I raised in
https://github.com/pandas-dev/pandas/pull/22105#issuecomment-409183567 may be somewhat challenging, but I haven't thought about them too deeply.
Closing as stale
Sorry I haven't had the time to update this PR @Remnan13 - please feel free to take a shot!