@@ -26,7 +26,6 @@ class TestFrameLegend:
26
26
)
27
27
def test_mixed_yerr (self ):
28
28
# https://github.com/pandas-dev/pandas/issues/39522
29
- import matplotlib as mpl
30
29
from matplotlib .collections import LineCollection
31
30
from matplotlib .lines import Line2D
32
31
@@ -46,8 +45,6 @@ def test_mixed_yerr(self):
46
45
47
46
def test_legend_false (self ):
48
47
# https://github.com/pandas-dev/pandas/issues/40044
49
- import matplotlib as mpl
50
-
51
48
df = DataFrame ({"a" : [1 , 1 ], "b" : [2 , 3 ]})
52
49
df2 = DataFrame ({"d" : [2.5 , 2.5 ]})
53
50
@@ -63,27 +60,31 @@ def test_legend_false(self):
63
60
assert result == expected
64
61
65
62
@td .skip_if_no_scipy
66
- def test_df_legend_labels ( self ):
67
- kinds = [ "line" , "bar" , "barh" , "kde" , "area" , "hist" ]
63
+ @ pytest . mark . parametrize ( "kind" , [ "line" , "bar" , "barh" , "kde" , "area" , "hist" ])
64
+ def test_df_legend_labels ( self , kind ):
68
65
df = DataFrame (np .random .rand (3 , 3 ), columns = ["a" , "b" , "c" ])
69
66
df2 = DataFrame (np .random .rand (3 , 3 ), columns = ["d" , "e" , "f" ])
70
67
df3 = DataFrame (np .random .rand (3 , 3 ), columns = ["g" , "h" , "i" ])
71
68
df4 = DataFrame (np .random .rand (3 , 3 ), columns = ["j" , "k" , "l" ])
72
69
73
- for kind in kinds :
74
- ax = df .plot (kind = kind , legend = True )
75
- _check_legend_labels (ax , labels = df .columns )
70
+ ax = df .plot (kind = kind , legend = True )
71
+ _check_legend_labels (ax , labels = df .columns )
76
72
77
- ax = df2 .plot (kind = kind , legend = False , ax = ax )
78
- _check_legend_labels (ax , labels = df .columns )
73
+ ax = df2 .plot (kind = kind , legend = False , ax = ax )
74
+ _check_legend_labels (ax , labels = df .columns )
79
75
80
- ax = df3 .plot (kind = kind , legend = True , ax = ax )
81
- _check_legend_labels (ax , labels = df .columns .union (df3 .columns ))
76
+ ax = df3 .plot (kind = kind , legend = True , ax = ax )
77
+ _check_legend_labels (ax , labels = df .columns .union (df3 .columns ))
82
78
83
- ax = df4 .plot (kind = kind , legend = "reverse" , ax = ax )
84
- expected = list (df .columns .union (df3 .columns )) + list (reversed (df4 .columns ))
85
- _check_legend_labels (ax , labels = expected )
79
+ ax = df4 .plot (kind = kind , legend = "reverse" , ax = ax )
80
+ expected = list (df .columns .union (df3 .columns )) + list (reversed (df4 .columns ))
81
+ _check_legend_labels (ax , labels = expected )
86
82
83
+ @td .skip_if_no_scipy
84
+ def test_df_legend_labels_secondary_y (self ):
85
+ df = DataFrame (np .random .rand (3 , 3 ), columns = ["a" , "b" , "c" ])
86
+ df2 = DataFrame (np .random .rand (3 , 3 ), columns = ["d" , "e" , "f" ])
87
+ df3 = DataFrame (np .random .rand (3 , 3 ), columns = ["g" , "h" , "i" ])
87
88
# Secondary Y
88
89
ax = df .plot (legend = True , secondary_y = "b" )
89
90
_check_legend_labels (ax , labels = ["a" , "b (right)" , "c" ])
@@ -92,6 +93,8 @@ def test_df_legend_labels(self):
92
93
ax = df3 .plot (kind = "bar" , legend = True , secondary_y = "h" , ax = ax )
93
94
_check_legend_labels (ax , labels = ["a" , "b (right)" , "c" , "g" , "h (right)" , "i" ])
94
95
96
+ @td .skip_if_no_scipy
97
+ def test_df_legend_labels_time_series (self ):
95
98
# Time Series
96
99
ind = date_range ("1/1/2014" , periods = 3 )
97
100
df = DataFrame (np .random .randn (3 , 3 ), columns = ["a" , "b" , "c" ], index = ind )
@@ -104,6 +107,13 @@ def test_df_legend_labels(self):
104
107
ax = df3 .plot (legend = True , ax = ax )
105
108
_check_legend_labels (ax , labels = ["a" , "b (right)" , "c" , "g" , "h" , "i" ])
106
109
110
+ @td .skip_if_no_scipy
111
+ def test_df_legend_labels_time_series_scatter (self ):
112
+ # Time Series
113
+ ind = date_range ("1/1/2014" , periods = 3 )
114
+ df = DataFrame (np .random .randn (3 , 3 ), columns = ["a" , "b" , "c" ], index = ind )
115
+ df2 = DataFrame (np .random .randn (3 , 3 ), columns = ["d" , "e" , "f" ], index = ind )
116
+ df3 = DataFrame (np .random .randn (3 , 3 ), columns = ["g" , "h" , "i" ], index = ind )
107
117
# scatter
108
118
ax = df .plot .scatter (x = "a" , y = "b" , label = "data1" )
109
119
_check_legend_labels (ax , labels = ["data1" ])
@@ -112,6 +122,10 @@ def test_df_legend_labels(self):
112
122
ax = df3 .plot .scatter (x = "g" , y = "h" , label = "data3" , ax = ax )
113
123
_check_legend_labels (ax , labels = ["data1" , "data3" ])
114
124
125
+ @td .skip_if_no_scipy
126
+ def test_df_legend_labels_time_series_no_mutate (self ):
127
+ ind = date_range ("1/1/2014" , periods = 3 )
128
+ df = DataFrame (np .random .randn (3 , 3 ), columns = ["a" , "b" , "c" ], index = ind )
115
129
# ensure label args pass through and
116
130
# index name does not mutate
117
131
# column names don't mutate
@@ -128,7 +142,7 @@ def test_df_legend_labels(self):
128
142
def test_missing_marker_multi_plots_on_same_ax (self ):
129
143
# GH 18222
130
144
df = DataFrame (data = [[1 , 1 , 1 , 1 ], [2 , 2 , 4 , 8 ]], columns = ["x" , "r" , "g" , "b" ])
131
- fig , ax = mpl .pyplot .subplots (nrows = 1 , ncols = 3 )
145
+ _ , ax = mpl .pyplot .subplots (nrows = 1 , ncols = 3 )
132
146
# Left plot
133
147
df .plot (x = "x" , y = "r" , linewidth = 0 , marker = "o" , color = "r" , ax = ax [0 ])
134
148
df .plot (x = "x" , y = "g" , linewidth = 1 , marker = "x" , color = "g" , ax = ax [0 ])
@@ -210,7 +224,7 @@ def test_missing_markers_legend_using_style(self):
210
224
}
211
225
)
212
226
213
- fig , ax = mpl .pyplot .subplots ()
227
+ _ , ax = mpl .pyplot .subplots ()
214
228
for kind in "ABC" :
215
229
df .plot ("X" , kind , label = kind , ax = ax , style = "." )
216
230
0 commit comments