BUG: Fix TimeFormatter behavior with fractional seconds
State: closed

- [x] closes #18478
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Visualization
description: plotting

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

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

```diff
@@            Coverage Diff             @@
##           master   #18552      +/-   ##
==========================================
- Coverage   91.63%   91.57%   -0.07%     
==========================================
  Files         154      153       -1     
  Lines       51422    51366      -56     
==========================================
- Hits        47123    47039      -84     
- Misses       4299     4327      +28
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.44% <100%> (-0.05%)` | :arrow_down: |
| #single | `40.73% <0%> (-0.21%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18552?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.22% <100%> (-1.3%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `82.34% <0%> (-0.58%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `95.64% <0%> (-0.15%)` | :arrow_down: |
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `93.8% <0%> (-0.04%)` | :arrow_down: |
| [pandas/tseries/frequencies.py](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvZnJlcXVlbmNpZXMucHk=) | `94.02% <0%> (-0.03%)` | :arrow_down: |
| [pandas/core/sparse/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3BhcnNlL2ZyYW1lLnB5) | `94.78% <0%> (-0.03%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.7% <0%> (-0.02%)` | :arrow_down: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.43% <0%> (-0.01%)` | :arrow_down: |
| ... and [6 more](https://codecov.io/gh/pandas-dev/pandas/pull/18552/diff?src=pr&el=tree-more) | |

------

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

@TomAugspurger 
Do you know why GH still says "changes requested"? I believe all comments are addressed.
Example code:
```python
ax = pandas.DataFrame({'A': 1}, index=[pydt.time(11, 2, 59, 899502), pydt.time(11, 3, 0, 123456)]).plot()
for l in ax.xaxis.get_majorticklabels():
    l.set_rotation(45)
    l.set_horizontalalignment('right')
```
Output before:
![eleven_before](https://user-images.githubusercontent.com/16715246/33796929-80e58a0e-dcfe-11e7-802e-298f6fdc1dec.png)

Output after:
![eleven_after](https://user-images.githubusercontent.com/16715246/33796931-88d898c8-dcfe-11e7-873e-a4561ae37fc0.png)

is it standard to only show the most resolved, IOW, ``11:03`` rather than ``11:03:00``, IOW we always want to show HH:MM:SS (but not show millis unless needed).
My original motivation to change the TimeFormatter was to get rid of the :SS since I was always plotting full days. But if you prefer, we can drop that commit.

I didn't discover the sub-second breakage from a real usecase, but while reading the code to figure out where I'd need to change it for the above.
> My original motivation to change the TimeFormatter was to get rid of the :SS since I was always plotting full days. But if you prefer, we can drop that commit.

do we do a similar thing for fractional datetimes? cc @TomAugspurger @jorisvandenbossche @tacaswell 

The ideal way would probably be to not show the seconds if they are zero for each tick position, and show them if they are non-zero for at least one tick position. But I don't know how to implement that.
For comparison some plots illustrating tick labels with datetimes. Code:
```python
fig, axes = plt.subplots(nrows=6, ncols=1, figsize=(6, 10))
for i, ut in enumerate(['H', 'min', 'S', 'ms', 'us', 'N']):
    dti = pandas.date_range('11:02:59.889502', periods=2, freq='200'+ut)
    pandas.DataFrame({'A': 1}, index=dti).plot(ax=axes[i])
    axes[i].set_title('delta t = 200'+ut, position=(0.5, 0.6))
    axes[i].text(0.5, 0.1, str(dti.max()-dti.min()), transform=axes[i].transAxes, ha='center')

plt.tight_layout()
```
Resulting output:
![datetime_ticklabels](https://user-images.githubusercontent.com/16715246/34063141-8c29738e-e1f0-11e7-918c-7363844186e1.png)


thanks @nmartensen