From 234aa780cf18e38fef5102c827087f784a341dbe Mon Sep 17 00:00:00 2001 From: Adam Greenhall Date: Mon, 11 Mar 2013 18:16:17 -0700 Subject: [PATCH 1/5] ylabels for secondary_y axis modified Selective Plotting on Secondary Y-axis example to show how to set ylabels for both left and right y axis --- doc/source/visualization.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/visualization.rst b/doc/source/visualization.rst index 8e2e37ffc11b8..3a4861308a837 100644 --- a/doc/source/visualization.rst +++ b/doc/source/visualization.rst @@ -131,7 +131,9 @@ keyword: plt.figure() @savefig frame_plot_secondary_y.png width=4.5in - df.plot(secondary_y=['A', 'B']) + ax = df.plot(secondary_y=['A', 'B']) + ax.set_ylabel('CD scale') + ax.right_ax.set_ylabel('AB scale') Note that the columns plotted on the secondary y-axis is automatically marked with "(right)" in the legend. To turn off the automatic marking, use the From 5ab5220966fc260d975fd4db53413f8378fed67b Mon Sep 17 00:00:00 2001 From: Adam Greenhall Date: Mon, 11 Mar 2013 18:16:17 -0700 Subject: [PATCH 2/5] DOC: ylabels for secondary_y axis modified Selective Plotting on Secondary Y-axis example to show how to set ylabels for both left and right y axis --- doc/source/visualization.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/visualization.rst b/doc/source/visualization.rst index 8e2e37ffc11b8..3a4861308a837 100644 --- a/doc/source/visualization.rst +++ b/doc/source/visualization.rst @@ -131,7 +131,9 @@ keyword: plt.figure() @savefig frame_plot_secondary_y.png width=4.5in - df.plot(secondary_y=['A', 'B']) + ax = df.plot(secondary_y=['A', 'B']) + ax.set_ylabel('CD scale') + ax.right_ax.set_ylabel('AB scale') Note that the columns plotted on the secondary y-axis is automatically marked with "(right)" in the legend. To turn off the automatic marking, use the From 0ff0f87df3651fe849801aceee608c6b270cc4a7 Mon Sep 17 00:00:00 2001 From: Adam Greenhall Date: Fri, 15 Mar 2013 17:05:13 -0700 Subject: [PATCH 3/5] DOC: display yaxis labels. fix duplicate image filename in visualization. --- doc/source/visualization.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/source/visualization.rst b/doc/source/visualization.rst index 3a4861308a837..ae6fd7b742b6d 100644 --- a/doc/source/visualization.rst +++ b/doc/source/visualization.rst @@ -129,12 +129,13 @@ keyword: .. ipython:: python plt.figure() - - @savefig frame_plot_secondary_y.png width=4.5in ax = df.plot(secondary_y=['A', 'B']) ax.set_ylabel('CD scale') + @savefig frame_plot_secondary_y.png width=4.5in ax.right_ax.set_ylabel('AB scale') + + Note that the columns plotted on the secondary y-axis is automatically marked with "(right)" in the legend. To turn off the automatic marking, use the ``mark_right=False`` keyword: @@ -143,7 +144,7 @@ with "(right)" in the legend. To turn off the automatic marking, use the plt.figure() - @savefig frame_plot_secondary_y.png width=4.5in + @savefig frame_plot_secondary_y_no_right.png width=4.5in df.plot(secondary_y=['A', 'B'], mark_right=False) From 38822d5093b2c39031c7bc69181c79a6fcab5c3c Mon Sep 17 00:00:00 2001 From: Adam Greenhall Date: Fri, 15 Mar 2013 17:53:04 -0700 Subject: [PATCH 4/5] BUG: fix scatter matrix axis labels for odd number of columns --- pandas/tools/plotting.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 1bc0d16bbbf1b..acaa3bcb217c6 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -178,7 +178,7 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False, ax.set_ylabel(a) ax.yaxis.set_ticks_position('left') ax.yaxis.set_label_position('left') - elif j == n - 1 and i % 2 == 1: + elif j == n - 1 and i % 2 == 1 and i < n - 1: ax.set_ylabel(a, visible=True) ax.yaxis.set_visible(True) ax.set_ylabel(a) @@ -188,8 +188,6 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False, # ax.grid(b=grid) axes[0, 0].yaxis.set_visible(False) - axes[n - 1, n - 1].xaxis.set_visible(False) - axes[n - 1, n - 1].yaxis.set_visible(False) axes[0, n - 1].yaxis.tick_right() for ax in axes.flat: From 0e1ed4973681cca3117db61015312a9a73d9167f Mon Sep 17 00:00:00 2001 From: Adam Greenhall Date: Mon, 18 Mar 2013 10:47:40 -0700 Subject: [PATCH 5/5] BUG: fix scatter matrix to have complete axis labels --- pandas/tools/plotting.py | 64 +++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index acaa3bcb217c6..e6d2b5157218c 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -157,38 +157,26 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False, ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) - # setup labels + # setup x axis labels if i == 0 and j % 2 == 1: - ax.set_xlabel(b, visible=True) - ax.xaxis.set_visible(True) - ax.set_xlabel(b) - ax.xaxis.set_ticks_position('top') - ax.xaxis.set_label_position('top') - setp(ax.get_xticklabels(), rotation=90) + # first row, odd column + _label_axis(ax, kind='x', label=b, position='top', rotate=True) elif i == n - 1 and j % 2 == 0: - ax.set_xlabel(b, visible=True) - ax.xaxis.set_visible(True) - ax.set_xlabel(b) - ax.xaxis.set_ticks_position('bottom') - ax.xaxis.set_label_position('bottom') - setp(ax.get_xticklabels(), rotation=90) - elif j == 0 and i % 2 == 0: - ax.set_ylabel(a, visible=True) - ax.yaxis.set_visible(True) - ax.set_ylabel(a) - ax.yaxis.set_ticks_position('left') - ax.yaxis.set_label_position('left') - elif j == n - 1 and i % 2 == 1 and i < n - 1: - ax.set_ylabel(a, visible=True) - ax.yaxis.set_visible(True) - ax.set_ylabel(a) - ax.yaxis.set_ticks_position('right') - ax.yaxis.set_label_position('right') + # last row, even column + _label_axis(ax, kind='x', label=b, position='bottom', rotate=True) + + # setup y axis labels + if j == 0 and i % 2 == 0: + # first column, even row + _label_axis(ax, kind='y', label=a, position='left') + elif j == n - 1 and i % 2 == 1: + # last column, odd row + _label_axis(ax, kind='y', label=a, position='right') # ax.grid(b=grid) - axes[0, 0].yaxis.set_visible(False) - axes[0, n - 1].yaxis.tick_right() + # axes[0, 0].yaxis.set_visible(False) + # axes[0, n - 1].yaxis.tick_right() for ax in axes.flat: setp(ax.get_xticklabels(), fontsize=8) @@ -196,6 +184,28 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False, return axes +def _label_axis(ax, kind='x', label='', position='top', + ticks=True, rotate=False): + + from matplotlib.artist import setp + if kind == 'x': + ax.set_xlabel(label, visible=True) + ax.xaxis.set_visible(True) + ax.xaxis.set_ticks_position(position) + ax.xaxis.set_label_position(position) + if rotate: + setp(ax.get_xticklabels(), rotation=90) + elif kind == 'y': + ax.yaxis.set_visible(True) + ax.set_ylabel(label, visible=True) + # ax.set_ylabel(a) + ax.yaxis.set_ticks_position(position) + ax.yaxis.set_label_position(position) + return + + + + def _gca(): import matplotlib.pyplot as plt