Skip to content
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

Scatter matrix labels fix #3063

Closed
Closed
8 changes: 5 additions & 3 deletions doc/source/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ keyword:
.. ipython:: python

plt.figure()
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')

@savefig frame_plot_secondary_y.png width=4.5in
df.plot(secondary_y=['A', 'B'])

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
Expand All @@ -141,7 +143,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)


Expand Down
64 changes: 36 additions & 28 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,47 +157,55 @@ 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')
# 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:
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 column, odd row
_label_axis(ax, kind='y', label=a, position='right')

# 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()
# 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)
setp(ax.get_yticklabels(), fontsize=8)

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
Expand Down