Skip to content

Commit ed36901

Browse files
mzeitlin11luckyvs1
authored andcommitted
TST: fix some mpl warnings (pandas-dev#38574)
1 parent b72976e commit ed36901

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

pandas/plotting/_matplotlib/misc.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ def normalize(series):
144144
df = frame.drop(class_column, axis=1).apply(normalize)
145145

146146
if ax is None:
147-
ax = plt.gca(xlim=[-1, 1], ylim=[-1, 1])
147+
ax = plt.gca()
148+
ax.set_xlim(-1, 1)
149+
ax.set_ylim(-1, 1)
148150

149151
to_plot: Dict[Label, List[List]] = {}
150152
colors = get_standard_colors(
@@ -260,7 +262,8 @@ def f(t):
260262
)
261263
colors = dict(zip(classes, color_values))
262264
if ax is None:
263-
ax = plt.gca(xlim=(-np.pi, np.pi))
265+
ax = plt.gca()
266+
ax.set_xlim(-np.pi, np.pi)
264267
for i in range(n):
265268
row = df.iloc[i].values
266269
f = function(row)
@@ -440,7 +443,9 @@ def autocorrelation_plot(
440443
n = len(series)
441444
data = np.asarray(series)
442445
if ax is None:
443-
ax = plt.gca(xlim=(1, n), ylim=(-1.0, 1.0))
446+
ax = plt.gca()
447+
ax.set_xlim(1, n)
448+
ax.set_ylim(-1.0, 1.0)
444449
mean = np.mean(data)
445450
c0 = np.sum((data - mean) ** 2) / float(n)
446451

pandas/tests/plotting/test_misc.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ def setup_method(self, method):
7171
def test_autocorrelation_plot(self):
7272
from pandas.plotting import autocorrelation_plot
7373

74-
_check_plot_works(autocorrelation_plot, series=self.ts)
75-
_check_plot_works(autocorrelation_plot, series=self.ts.values)
74+
# Ensure no UserWarning when making plot
75+
with tm.assert_produces_warning(None):
76+
_check_plot_works(autocorrelation_plot, series=self.ts)
77+
_check_plot_works(autocorrelation_plot, series=self.ts.values)
7678

77-
ax = autocorrelation_plot(self.ts, label="Test")
79+
ax = autocorrelation_plot(self.ts, label="Test")
7880
self._check_legend_labels(ax, labels=["Test"])
7981

8082
def test_lag_plot(self):
@@ -132,8 +134,9 @@ def test_andrews_curves(self, iris):
132134
from pandas.plotting import andrews_curves
133135

134136
df = iris
135-
136-
_check_plot_works(andrews_curves, frame=df, class_column="Name")
137+
# Ensure no UserWarning when making plot
138+
with tm.assert_produces_warning(None):
139+
_check_plot_works(andrews_curves, frame=df, class_column="Name")
137140

138141
rgba = ("#556270", "#4ECDC4", "#C7F464")
139142
ax = _check_plot_works(
@@ -280,7 +283,9 @@ def test_radviz(self, iris):
280283
from pandas.plotting import radviz
281284

282285
df = iris
283-
_check_plot_works(radviz, frame=df, class_column="Name")
286+
# Ensure no UserWarning when making plot
287+
with tm.assert_produces_warning(None):
288+
_check_plot_works(radviz, frame=df, class_column="Name")
284289

285290
rgba = ("#556270", "#4ECDC4", "#C7F464")
286291
ax = _check_plot_works(radviz, frame=df, class_column="Name", color=rgba)

0 commit comments

Comments
 (0)