BUG: Plotting use FixedLocator
State: closed

For string x values or multiindex, the axis locator is now set to a
FixedLocator for Line and Area plot. The ticklabel stay consistent
when scaling and zooming.

closes #7612 
closes #15912
closes #22334
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Bug
name: Visualization
description: plotting

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

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

```diff
@@            Coverage Diff             @@
##           master   #26185      +/-   ##
==========================================
- Coverage   91.98%   91.97%   -0.02%     
==========================================
  Files         175      175              
  Lines       52371    52379       +8     
==========================================
+ Hits        48175    48176       +1     
- Misses       4196     4203       +7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.53% <50%> (-0.01%)` | :arrow_down: |
| #single | `40.69% <0%> (-0.16%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `83.57% <50%> (-0.2%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.9% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.71% <0%> (+0.1%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26185?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/26185?src=pr&el=footer). Last update [fecee8f...2e732b1](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=h1) Report
> Merging [#26185](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/fecee8ffe39446d213f425257c6de24b5a7f9021?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `50%`.

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

```diff
@@            Coverage Diff             @@
##           master   #26185      +/-   ##
==========================================
- Coverage   91.98%   91.97%   -0.02%     
==========================================
  Files         175      175              
  Lines       52371    52379       +8     
==========================================
+ Hits        48175    48176       +1     
- Misses       4196     4203       +7
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.53% <50%> (-0.01%)` | :arrow_down: |
| #single | `40.69% <0%> (-0.16%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `83.57% <50%> (-0.2%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.9% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.71% <0%> (+0.1%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26185?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/26185?src=pr&el=footer). Last update [fecee8f...2e732b1](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=h1) Report
> Merging [#26185](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/fecee8ffe39446d213f425257c6de24b5a7f9021?src=pr&el=desc) will **decrease** coverage by `0.02%`.
> The diff coverage is `55.55%`.

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

```diff
@@            Coverage Diff             @@
##           master   #26185      +/-   ##
==========================================
- Coverage   91.98%   91.96%   -0.03%     
==========================================
  Files         175      175              
  Lines       52371    52375       +4     
==========================================
- Hits        48175    48165      -10     
- Misses       4196     4210      +14
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.51% <55.55%> (-0.03%)` | :arrow_down: |
| #single | `40.68% <0%> (-0.17%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `83.63% <55.55%> (-0.14%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/indexing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhpbmcucHk=) | `90.53% <0%> (-0.35%)` | :arrow_down: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.72% <0%> (-0.27%)` | :arrow_down: |
| [pandas/core/computation/engines.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZW5naW5lcy5weQ==) | `88.33% <0%> (-0.2%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.9% <0%> (-0.12%)` | :arrow_down: |
| [pandas/core/arrays/\_ranges.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL19yYW5nZXMucHk=) | `98.64% <0%> (-0.02%)` | :arrow_down: |
| [pandas/core/accessor.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYWNjZXNzb3IucHk=) | `98.79% <0%> (-0.02%)` | :arrow_down: |
| [pandas/core/internals/blocks.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL2Jsb2Nrcy5weQ==) | `94.07% <0%> (-0.02%)` | :arrow_down: |
| [pandas/io/formats/csvs.py](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvY3N2cy5weQ==) | `98.19% <0%> (-0.02%)` | :arrow_down: |
| ... and [39 more](https://codecov.io/gh/pandas-dev/pandas/pull/26185/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26185?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/26185?src=pr&el=footer). Last update [fecee8f...863ba3d](https://codecov.io/gh/pandas-dev/pandas/pull/26185?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Please add tests to cover the issues being closed
Hello @nrebena! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:





There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2019-04-30 08:36:55 UTC
I added tests for the issue. I used the example from #22334.
```
        df = pd.DataFrame({'sales': [3, 2, 3],
                           'visits': [20, 42, 28], 
                           'day': ['Monday', 'Tuesday', 'Wednesday']})
        ax = df.plot.area(x='day')
        ax.set_xlim(-1, 3)
        xticklabels = [t.get_text() for t in ax.get_xticklabels()]
        labels_position = dict(zip(xticklabels, ax.get_xticks()))
        # Testing if the label stayed at the right position
        assert labels_position['Monday'] == 0.0
        assert labels_position['Tuesday'] == 1.0
        assert labels_position['Wednesday'] == 2.0
```
![Figure_1](https://user-images.githubusercontent.com/49879400/56582059-aceb0180-65d6-11e9-81e6-c5abb4f952cb.png)

This should guarantee that the xticklabel stay at the same position even after a change in the axis.
I am open for idea if there is a better way to test for the issues.


I added the whatsnew entry, and splitted the test in two, one for string index and one for multiindex, as this was one of the difference between the issues, even if the solution is the same.


does this fix  #11465 ? (which is marked as a duplicate); can you add a test for this one as well.
I already looked into it, and this doesnt fix #11465, and neither #2980. These are not duplicate and should maybe be reopen.
The way bar plot handle tick position is very different from how it is done in line plot, and it deal with ticks in its own peculiar way. I think I will look into them for my next PR hopefully :smiley:
thanks @nrebena 
welcome patches for other issues!