BUG: Enable plotting with PeriodIndex with arbitrary frequencies, resolves #14763
State: closed

- [x] closes #14763 
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

Enables plotting of data with PeriodIndex with frequencies which are multiples of the `data.index.freq.rule_code`.
Hopefully I'll find some time to include tests within the next 3 weeks. Since this is my first pull requests, I may need some additional time to write tests.

Labels:
name: Visualization
description: plotting

Comments:
Yes, I absolutely agree. Since this is my first PR, I am not sure how to write good tests. I altered `test_datetimelike` to include combinations of the frequencies. Hopefully this is ok, otherwise I'll add more tests in the next weeks.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26241?src=pr&el=h1) Report
> Merging [#26241](https://codecov.io/gh/pandas-dev/pandas/pull/26241?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9feb3ad92cc0397a04b665803a49299ee7aa1037?src=pr&el=desc) will **decrease** coverage by `51.28%`.
> The diff coverage is `0%`.

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

```diff
@@             Coverage Diff             @@
##           master   #26241       +/-   ##
===========================================
- Coverage   91.97%   40.69%   -51.29%     
===========================================
  Files         175      175               
  Lines       52368    52371        +3     
===========================================
- Hits        48164    21310    -26854     
- Misses       4204    31061    +26857
```

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

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26241?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_timeseries.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL190aW1lc2VyaWVzLnB5) | `0% <0%> (-65.29%)` | :arrow_down: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `0% <0%> (-99.37%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.16%)` | :arrow_down: |
| [pandas/io/sas/sas\_xport.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfeHBvcnQucHk=) | `0% <0%> (-90.1%)` | :arrow_down: |
| [pandas/core/tools/numeric.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdG9vbHMvbnVtZXJpYy5weQ==) | `10.44% <0%> (-89.56%)` | :arrow_down: |
| ... and [131 more](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26241?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/26241?src=pr&el=footer). Last update [9feb3ad...53441fe](https://codecov.io/gh/pandas-dev/pandas/pull/26241?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/26241?src=pr&el=h1) Report
> Merging [#26241](https://codecov.io/gh/pandas-dev/pandas/pull/26241?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/65eac80dd4113ddbcee876029bfe03b4b3f11a3d?src=pr&el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #26241      +/-   ##
==========================================
+ Coverage   91.75%   91.76%   +0.01%     
==========================================
  Files         174      174              
  Lines       50761    50632     -129     
==========================================
- Hits        46575    46462     -113     
+ Misses       4186     4170      -16
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.3% <100%> (+0.04%)` | :arrow_up: |
| #single | `41.7% <0%> (-0.1%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26241?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_timeseries.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL190aW1lc2VyaWVzLnB5) | `65.81% <100%> (+0.53%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/indexes/frozen.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9mcm96ZW4ucHk=) | `91.78% <0%> (-0.33%)` | :arrow_down: |
| [pandas/io/excel/\_base.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2V4Y2VsL19iYXNlLnB5) | `91.81% <0%> (-0.33%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97% <0%> (-0.14%)` | :arrow_down: |
| [pandas/core/sparse/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL3Nlcmllcy5weQ==) | `93.18% <0%> (-0.13%)` | :arrow_down: |
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `83.77% <0%> (-0.13%)` | :arrow_down: |
| [pandas/core/internals/managers.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW50ZXJuYWxzL21hbmFnZXJzLnB5) | `93.87% <0%> (-0.06%)` | :arrow_down: |
| [pandas/core/series.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc2VyaWVzLnB5) | `93.61% <0%> (-0.06%)` | :arrow_down: |
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.91% <0%> (-0.05%)` | :arrow_down: |
| ... and [12 more](https://codecov.io/gh/pandas-dev/pandas/pull/26241/diff?src=pr&el=tree-more) | |

------

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

> 
> 
> Tests are hugely critical - if you could add will take a look

@WillAyd I added some tests. I assumed that it is ok to alter existing tests.
The last 2 tests using `tsplot` still fail and I don't know how to solve this. Of course I could set the index with
```
for s in self.period_ser:
    s.index = s.index.asfreq(s.index.freq.rule_code)
    _check_plot_works(f, s.index.freq.rule_code, ax=ax, series=s)
```

But this doesn't seem like a good solution. Any advice?
Rather than modifying existing tests I think you'd be better off creating a new test specifically for this feature. 

Also looks like these changes caused a failure in the CI as is so be sure to give that a look
> 
> 
> Rather than modifying existing tests I think you'd be better off creating a new test specifically for this feature.
> 
> Also looks like these changes caused a failure in the CI as is so be sure to give that a look

Done. All checks passing now. Any other recommendations/changes?
Ok, both done. Thanks alot for your advice!
Any other remarks/advice/changes?
Hello @JoElfner! 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-05-27 10:53:43 UTC
Thanks @JoElfner!
> 
> 
> Thanks @JoElfner!

You are welcome and thanks for your help and advice!
My next PR will be more straightforward. :)