-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: Add the ability to have a separate title for each subplot when plotting #14753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
3f133ac
55f4667
8d1b598
ecb9453
d6d1b0c
94ea2d3
eb43f25
5586a96
aa5bb98
2059339
7a293ef
301cc7d
5b88951
c206daf
59ab880
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,11 @@ | |
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works, | ||
_ok_for_gaussian_kde) | ||
|
||
|
||
""" Test cases for misc plot functions """ | ||
|
||
|
||
@tm.mplskip | ||
class TestSeriesPlots(TestPlotBase): | ||
|
||
def setUp(self): | ||
TestPlotBase.setUp(self) | ||
import matplotlib as mpl | ||
|
@@ -54,7 +52,6 @@ def test_bootstrap_plot(self): | |
|
||
@tm.mplskip | ||
class TestDataFramePlots(TestPlotBase): | ||
|
||
@slow | ||
def test_scatter_plot_legacy(self): | ||
tm._skip_if_no_scipy() | ||
|
@@ -277,6 +274,24 @@ def test_radviz(self): | |
handles, labels = ax.get_legend_handles_labels() | ||
self._check_colors(handles, facecolors=colors) | ||
|
||
@slow | ||
def test_subplot_titles(self): | ||
df = self.iris.drop('Name', axis=1).head() | ||
# Use the column names as the subplot titles | ||
title = list(df.columns) | ||
|
||
# Case len(title) == len(df) | ||
plot = df.plot(subplots=True, title=title) | ||
self.assertEqual([p.title._text for p in plot], title) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I missed this earlier, but can you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh cool I didn't know that existed! Just pushed with the change. |
||
|
||
# Case len(title) > len(df) | ||
plot = df.plot(subplots=True, title=title + ['Ignore me!']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should raise if length of passed list and number of axes are different. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good I added exceptions and pushed. Is ValueError appropriate here? |
||
self.assertEqual([p.title._text for p in plot], title) | ||
|
||
# Case len(title) < len(df) | ||
plot = df.plot(subplots=True, title=title[:2]) | ||
self.assertEqual([p.title._text for p in plot], title[:2] + ['', '']) | ||
|
||
|
||
if __name__ == '__main__': | ||
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1217,7 +1217,11 @@ def _adorn_subplots(self): | |
|
||
if self.title: | ||
if self.subplots: | ||
self.fig.suptitle(self.title) | ||
if is_list_like(self.title): | ||
for (ax, title) in zip(self.axes, self.title): | ||
ax.set_title(title) | ||
else: | ||
self.fig.suptitle(self.title) | ||
else: | ||
self.axes[0].set_title(self.title) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should raise if |
||
|
||
|
@@ -2555,8 +2559,12 @@ def _plot(data, x=None, y=None, subplots=False, | |
figsize : a tuple (width, height) in inches | ||
use_index : boolean, default True | ||
Use index as ticks for x axis | ||
title : string | ||
Title to use for the plot | ||
title : string or list | ||
If a string is passed, print the string at the top of the figure. If a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you leave the starting sentence "Title to use for the plot" ? |
||
list of strings is passed and subplots is True, print the the first | ||
string above the first subplot, the second string above the second | ||
subplot, and so forth until the end of the list is reached or there are | ||
no more subplots. | ||
grid : boolean, default None (matlab style default) | ||
Axis grid lines | ||
legend : False/True/'reverse' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add this PR number in the issue tag (:issue:
14753
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)