TST: fix warnings on multiple subplots
State: closed

- [ ] xref #37178 partially
- [ ] tests added / passed
- [ ] passes `black pandas`
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

This PR suggests a (partial) fix for such warnings, which take place when running test suite on ``pandas/tests/plotting``.
```
UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
```

The problem is the following.
The function ``_check_plot_works`` creates subplot(211) if axes are not provided.
This is fine, when the plot to be created is a single-axes plot.
However, if the plot itself is to be plotted on multiple axes (for instance, df.hist would plot each column on a dedicated subplot, by default), then the warnings mentioned are emitted.

Two ways to handle it:
- Find cases where plot is a multiaxes-plot and catch warnings there. This is fine, but in some parametrized tests the plots are either single-axes or multiple-axes. It makes it difficult to figure out without splitting the tests.
- Change function ``_check_plot_works``: do not create subplot(211).

I created ``_check_single_plot_works`` which does not create subplots and used it in the problematic cases.
I guess, that the name is not the best (I would prefer ``_check_plot_works``), but I encourage those concerned to have a discussion here.

Please see comments in ``_check_plot_works`` (I will remove them once we come to the conclusion on the topic).

Labels:
name: Testing
description: pandas testing functions or related to the test suite

Comments:
Tests related to datetime failed in in Linux py38_locale. Should be unrelated to the topic.
looks fine to me. @charlesdong1991 @simonjayhawkins @WillAyd if any comments.
Can you merge master again? Is the Windows failure not related?
> 
> 
> I'm not familiar with the code here. Is there a solution without so much code duplication?

I can extract portions of the code from ``_check_plot_works``, so that the duplication is reduced.
For that I will refactor ``_check_plot_works``.
However, before doing so, it seems reasonable to figure out whether we need to split ``_check_plot_works`` into multiple functions (for example, check_single_plot_works, check_subplots_works, check_bootstrap_plot_works).

@charlesdong1991 
is adding an extra keyword argument to _check_plot_works not an option?
> 
> 
> is adding an extra keyword argument to _check_plot_works not an option?

I tried to implement a parameter ``force_subplots = True`` (by default create plots in two subplots), and get rid of ``_check_single_plot_works``, but the logic is too complex (and too many levels of indentation).
> 
> 
> Can you merge master again? Is the Windows failure not related?

Tests on windows failed now because of internal CI problem.
@ivanovmg can you merge master and update to comments
we need to combine these check_plot_works to a single function (add an arg to differentiate them)
> 
> 
> > is adding an extra keyword argument to _check_plot_works not an option?
> 
> I tried to implement a parameter `force_subplots = True` (by default create plots in two subplots), and get rid of `_check_single_plot_works`, but the logic is too complex (and too many levels of indentation).

I figured out how to implement it with an optional keyword argument.
Please have a look.
@jreback @charlesdong1991 @jreback 
lgtm @charlesdong1991 @WillAyd if any comments
would be nicer to put a sentence in docs to briefly explain the new added kwarg a bit

but also okay if merge ^^
> 
> 
> would be nicer to put a sentence in docs to briefly explain the new added kwarg a bit
> 
> but also okay if merge ^^

I added the docstring. Please take a look.
great work! @ivanovmg 
thanks @ivanovmg