Skip to content

Commit 7c54141

Browse files
committed
1 parent 90842ba commit 7c54141

File tree

3 files changed

+55
-18
lines changed

3 files changed

+55
-18
lines changed

pandas/tests/test_graphics.py

+30-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ def test_bar_colors(self):
6969
rects = ax.patches
7070

7171
conv = colors.colorConverter
72-
for i, rect in enumerate(rects[:5]):
72+
for i, rect in enumerate(rects[::5]):
7373
xp = conv.to_rgba(default_colors[i])
7474
rs = rect.get_facecolor()
75-
self.assert_(xp, rs)
75+
self.assert_(xp == rs)
7676

7777
plt.close('all')
7878

@@ -81,11 +81,37 @@ def test_bar_colors(self):
8181
rects = ax.patches
8282

8383
conv = colors.colorConverter
84-
for i, rect in enumerate(rects[:5]):
84+
for i, rect in enumerate(rects[::5]):
8585
xp = conv.to_rgba(custom_colors[i])
8686
rs = rect.get_facecolor()
87-
self.assert_(xp, rs)
87+
self.assert_(xp == rs)
8888

89+
@slow
90+
def test_bar_linewidth(self):
91+
df = DataFrame(np.random.randn(5, 5))
92+
93+
# regular
94+
ax = df.plot(kind='bar', linewidth=2)
95+
for r in ax.patches:
96+
self.assert_(r.get_linewidth() == 2)
97+
98+
# stacked
99+
ax = df.plot(kind='bar', stacked=True, linewidth=2)
100+
for r in ax.patches:
101+
self.assert_(r.get_linewidth() == 2)
102+
103+
# subplots
104+
axes = df.plot(kind='bar', linewidth=2, subplots=True)
105+
for ax in axes:
106+
for r in ax.patches:
107+
self.assert_(r.get_linewidth() == 2)
108+
109+
@slow
110+
def test_1rotation(self):
111+
df = DataFrame(np.random.randn(5, 5))
112+
ax = df.plot(rot=30)
113+
for l in ax.get_xticklabels():
114+
self.assert_(l.get_rotation() == 30)
89115

90116
@slow
91117
def test_irregular_datetime(self):

pandas/tools/plotting.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -996,16 +996,23 @@ def _maybe_convert_index(self, data):
996996
def _post_plot_logic(self):
997997
df = self.data
998998

999-
condition = (not self._use_dynamic_x
999+
condition = (not self._use_dynamic_x()
10001000
and df.index.is_all_dates
10011001
and not self.subplots
10021002
or (self.subplots and self.sharex))
10031003

10041004
index_name = self._get_index_name()
10051005

1006+
rot = 30
1007+
if self.rot is not None:
1008+
rot = self.rot
1009+
10061010
for ax in self.axes:
10071011
if condition:
1008-
format_date_labels(ax)
1012+
format_date_labels(ax, rot=rot)
1013+
elif self.rot is not None:
1014+
for l in ax.get_xticklabels():
1015+
l.set_rotation(self.rot)
10091016

10101017
if index_name is not None:
10111018
ax.set_xlabel(index_name)
@@ -1016,6 +1023,7 @@ def _post_plot_logic(self):
10161023

10171024

10181025
class BarPlot(MPLPlot):
1026+
10191027
_default_rot = {'bar' : 90, 'barh' : 0}
10201028

10211029
def __init__(self, data, **kwargs):
@@ -1027,12 +1035,6 @@ def _args_adjust(self):
10271035
if self.rot is None:
10281036
self.rot = self._default_rot[self.kind]
10291037

1030-
if self.fontsize is None:
1031-
if len(self.data) < 10:
1032-
self.fontsize = 12
1033-
else:
1034-
self.fontsize = 10
1035-
10361038
@property
10371039
def bar_f(self):
10381040
if self.kind == 'bar':
@@ -1066,15 +1068,13 @@ def _make_plot(self):
10661068

10671069
if self.subplots:
10681070
ax = self._get_ax(i) #self.axes[i]
1069-
rect = bar_f(ax, self.ax_pos, y, 0.5, start=pos_prior,
1070-
linewidth=1, **kwds)
1071+
rect = bar_f(ax, self.ax_pos, y, 0.5, start=pos_prior, **kwds)
10711072
ax.set_title(label)
10721073
elif self.stacked:
10731074
mask = y > 0
10741075
start = np.where(mask, pos_prior, neg_prior)
1075-
10761076
rect = bar_f(ax, self.ax_pos, y, 0.5, start=start,
1077-
label=label, linewidth=1, **kwds)
1077+
label=label, **kwds)
10781078
pos_prior = pos_prior + np.where(mask, y, 0)
10791079
neg_prior = neg_prior + np.where(mask, 0, y)
10801080
else:
@@ -1385,12 +1385,12 @@ def _stringify(x):
13851385
return str(x)
13861386

13871387

1388-
def format_date_labels(ax):
1388+
def format_date_labels(ax, rot):
13891389
# mini version of autofmt_xdate
13901390
try:
13911391
for label in ax.get_xticklabels():
13921392
label.set_ha('right')
1393-
label.set_rotation(30)
1393+
label.set_rotation(rot)
13941394
fig = ax.get_figure()
13951395
fig.subplots_adjust(bottom=0.2)
13961396
except Exception: # pragma: no cover

pandas/tseries/tests/test_plotting.py

+11
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,17 @@ def test_secondary_legend(self):
800800
colors.add(line.get_color())
801801
self.assert_(len(colors) == 4)
802802

803+
@slow
804+
def test_format_date_axis(self):
805+
rng = date_range('1/1/2012', periods=12, freq='M')
806+
df = DataFrame(np.random.randn(len(rng), 3), rng)
807+
ax = df.plot()
808+
xaxis = ax.get_xaxis()
809+
for l in xaxis.get_ticklabels():
810+
if len(l.get_text()) > 0:
811+
self.assert_(l.get_rotation() == 30)
812+
813+
803814
PNG_PATH = 'tmp.png'
804815
def _check_plot_works(f, freq=None, series=None, *args, **kwargs):
805816
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)