PERF: Period plotting performance
State: closed

Setup

```python
In [3]: N = 2000
   ...: M = 5
   ...: idx = date_range('1/1/1975', periods=N)
   ...: df = DataFrame(np.random.randn(N, M), index=idx)
```

0.23.4:

```python
In [3]: %time df.plot()
CPU times: user 274 ms, sys: 66.7 ms, total: 340 ms
Wall time: 377 ms
Out[3]: <matplotlib.axes._subplots.AxesSubplot at 0x11eda6128>
```

HEAD:

```python
In [4]: %time df.plot()
CPU times: user 141 ms, sys: 32.6 ms, total: 173 ms
Wall time: 194 ms
Out[4]: <matplotlib.axes._subplots.AxesSubplot at 0x11550a5f8>
```

Closes https://github.com/pandas-dev/pandas/issues/24304

Labels:
name: Visualization
description: plotting
name: Performance
description: Memory or execution speed performance

Comments:
Hello @TomAugspurger! Thanks for submitting the PR.

 - There are no PEP8 issues in the file [`pandas/plotting/_converter.py`](https://github.com/TomAugspurger/pandas/blob/0239cfbb5b4e692f4e9c9d4d141331bbbaaaba1a/pandas/plotting/_converter.py) !


cc @jorisvandenbossche.

The slowdown was operating element wise on an ndarray of Period objects. The array was coming from matplotlib.

I'm not sure if we always got the ndarray of Period objects and previously handled them differently, or if something changed on MPL's end to convert what we're giving them (PeriodIndex) to an ndarray.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24308?src=pr&el=h1) Report
> Merging [#24308](https://codecov.io/gh/pandas-dev/pandas/pull/24308?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/41681c89df25e78d072c862feabe24ec715eed54?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `66.66%`.

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

```diff
@@            Coverage Diff             @@
##           master   #24308      +/-   ##
==========================================
+ Coverage   92.28%   92.28%   +<.01%     
==========================================
  Files         162      162              
  Lines       51827    51829       +2     
==========================================
+ Hits        47827    47829       +2     
  Misses       4000     4000
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.68% <66.66%> (ø)` | :arrow_up: |
| #single | `43.01% <33.33%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24308?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/24308/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.78% <66.66%> (+0.1%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24308?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/24308?src=pr&el=footer). Last update [41681c8...3f6903b](https://codecov.io/gh/pandas-dev/pandas/pull/24308?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/24308?src=pr&el=h1) Report
> Merging [#24308](https://codecov.io/gh/pandas-dev/pandas/pull/24308?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/41681c89df25e78d072c862feabe24ec715eed54?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #24308      +/-   ##
==========================================
+ Coverage   92.28%   92.28%   +<.01%     
==========================================
  Files         162      162              
  Lines       51827    51831       +4     
==========================================
+ Hits        47827    47833       +6     
+ Misses       4000     3998       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.69% <100%> (ø)` | :arrow_up: |
| #single | `43% <20%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24308?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/24308/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.82% <100%> (+0.14%)` | :arrow_up: |
| [pandas/core/indexes/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/24308/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9wZXJpb2QucHk=) | `93.06% <0%> (ø)` | :arrow_up: |
| [pandas/core/arrays/datetimelike.py](https://codecov.io/gh/pandas-dev/pandas/pull/24308/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2RhdGV0aW1lbGlrZS5weQ==) | `96.44% <0%> (ø)` | :arrow_up: |
| [pandas/core/arrays/period.py](https://codecov.io/gh/pandas-dev/pandas/pull/24308/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL3BlcmlvZC5weQ==) | `98.5% <0%> (+0.01%)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/24308/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `87.58% <0%> (+0.09%)` | :arrow_up: |

------

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

lgtm.