Skip to content

Commit 981036d

Browse files
committed
Merge pull request #3073 from qwhelan/series_figsize
Fix figsize issue when using matplotlib locally
2 parents 54f1fc1 + 625d0bb commit 981036d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pandas/tests/test_graphics.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def test_plot(self):
6565

6666
Series(np.random.randn(10)).plot(kind='bar', color='black')
6767

68+
# figsize and title
69+
import matplotlib.pyplot as plt
70+
plt.close('all')
71+
ax = self.series.plot(title='Test', figsize=(16, 8))
72+
73+
self.assert_(ax.title.get_text() == 'Test')
74+
self.assert_((np.round(ax.figure.get_size_inches())
75+
== np.array((16., 8.))).all())
76+
6877
@slow
6978
def test_bar_colors(self):
7079
import matplotlib.pyplot as plt

pandas/tools/plotting.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ def _maybe_right_yaxis(self, ax):
813813
new_ax._get_lines.color_cycle = orig_ax._get_lines.color_cycle
814814

815815
orig_ax.right_ax, new_ax.left_ax = new_ax, orig_ax
816+
new_ax.right_ax = new_ax
816817

817818
if len(orig_ax.get_lines()) == 0: # no data on left y
818819
orig_ax.get_yaxis().set_visible(False)
@@ -1573,6 +1574,7 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
15731574
For line plots, use log scaling on y axis
15741575
secondary_y : boolean or sequence of ints, default False
15751576
If True then y-axis will be on the right
1577+
figsize : a tuple (width, height) in inches
15761578
kwds : keywords
15771579
Options to pass to matplotlib plotting method
15781580
@@ -1588,7 +1590,18 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
15881590
elif kind == 'kde':
15891591
klass = KdePlot
15901592

1591-
if ax is None:
1593+
"""
1594+
If no axis is specified, we check whether there are existing figures.
1595+
If so, we get the current axis and check whether yaxis ticks are on the
1596+
right. Ticks for the plot of the series will be on the right unless
1597+
there is at least one axis with ticks on the left.
1598+
1599+
If we do not check for whether there are existing figures, _gca() will
1600+
create a figure with the default figsize, causing the figsize= parameter to
1601+
be ignored.
1602+
"""
1603+
import matplotlib.pyplot as plt
1604+
if ax is None and len(plt.get_fignums()) > 0:
15921605
ax = _gca()
15931606
if ax.get_yaxis().get_ticks_position().strip().lower() == 'right':
15941607
fig = _gcf()
@@ -1612,7 +1625,8 @@ def plot_series(series, label=None, kind='line', use_index=True, rot=None,
16121625
plot_obj.generate()
16131626
plot_obj.draw()
16141627

1615-
return plot_obj.ax
1628+
# plot_obj.ax is None if we created the first figure
1629+
return plot_obj.axes[0]
16161630

16171631

16181632
def boxplot(data, column=None, by=None, ax=None, fontsize=None,

0 commit comments

Comments
 (0)