| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,7 +103,6 @@ Ticks, tick labels and Offset text | |||
| 103 | 103 | Axis.get_gridlines | |
| 104 | 104 | Axis.grid | |
| 105 | 105 | ||
| 106 | - Axis.iter_ticks | ||
| 107 | 106 | Axis.set_tick_params | |
| 108 | 107 | ||
| 109 | 108 | Axis.axis_date | |
@@ -365,7 +364,6 @@ YAxis | |||
| 365 | 364 | YAxis.get_units | |
| 366 | 365 | YAxis.get_view_interval | |
| 367 | 366 | YAxis.grid | |
| 368 | - YAxis.iter_ticks | ||
| 369 | 367 | YAxis.limit_range_for_scale | |
| 370 | 368 | YAxis.pan | |
| 371 | 369 | YAxis.reset_ticks | |
@@ -432,7 +430,6 @@ XAxis | |||
| 432 | 430 | XAxis.get_units | |
| 433 | 431 | XAxis.get_view_interval | |
| 434 | 432 | XAxis.grid | |
| 435 | - XAxis.iter_ticks | ||
| 436 | 433 | XAxis.limit_range_for_scale | |
| 437 | 434 | XAxis.pan | |
| 438 | 435 | XAxis.reset_ticks | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + Changes to the internal tick handling API | ||
| 2 | + ````````````````````````````````````````` | ||
| 3 | + | ||
| 4 | + ``Axis.iter_ticks`` (which only served as a helper to the private | ||
| 5 | + ``Axis._update_ticks``) is deprecated. | ||
| 6 | + | ||
| 7 | + The signature of the (private) ``Axis._update_ticks`` has been changed to not | ||
| 8 | + take the renderer as argument anymore (that argument is unused). | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1016,6 +1016,7 @@ def _set_artist_props(self, a): | |||
| 1016 | 1016 | return | |
| 1017 | 1017 | a.set_figure(self.figure) | |
| 1018 | 1018 | ||
| 1019 | + @cbook.deprecated("3.1") | ||
| 1019 | 1020 | def iter_ticks(self): | |
| 1020 | 1021 | """ | |
| 1021 | 1022 | Yield ``(Tick, location, label)`` tuples for major and minor ticks. | |
@@ -1035,7 +1036,7 @@ def get_ticklabel_extents(self, renderer): | |||
| 1035 | 1036 | of the axes. | |
| 1036 | 1037 | """ | |
| 1037 | 1038 | ||
| 1038 | - ticks_to_draw = self._update_ticks(renderer) | ||
| 1039 | + ticks_to_draw = self._update_ticks() | ||
| 1039 | 1040 | ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw, | |
| 1040 | 1041 | renderer) | |
| 1041 | 1042 | ||
@@ -1058,20 +1059,38 @@ def get_smart_bounds(self): | |||
| 1058 | 1059 | """get whether the axis has smart bounds""" | |
| 1059 | 1060 | return self._smart_bounds | |
| 1060 | 1061 | ||
| 1061 | - def _update_ticks(self, renderer): | ||
| 1062 | + def _update_ticks(self): | ||
| 1062 | 1063 | """ | |
| 1063 | - Update ticks (position and labels) using the current data | ||
| 1064 | - interval of the axes. Returns a list of ticks that will be | ||
| 1065 | - drawn. | ||
| 1064 | + Update ticks (position and labels) using the current data interval of | ||
| 1065 | + the axes. Return the list of ticks that will be drawn. | ||
| 1066 | 1066 | """ | |
| 1067 | 1067 | ||
| 1068 | - interval = self.get_view_interval() | ||
| 1069 | - tick_tups = list(self.iter_ticks()) # iter_ticks calls the locator | ||
| 1070 | - if self._smart_bounds and tick_tups: | ||
| 1068 | + major_locs = self.major.locator() | ||
| 1069 | + major_ticks = self.get_major_ticks(len(major_locs)) | ||
| 1070 | + self.major.formatter.set_locs(major_locs) | ||
| 1071 | + major_labels = self.major.formatter.format_ticks(major_locs) | ||
| 1072 | + for tick, loc, label in zip(major_ticks, major_locs, major_labels): | ||
| 1073 | + tick.update_position(loc) | ||
| 1074 | + tick.set_label1(label) | ||
| 1075 | + tick.set_label2(label) | ||
| 1076 | + minor_locs = self.minor.locator() | ||
| 1077 | + minor_ticks = self.get_minor_ticks(len(minor_locs)) | ||
| 1078 | + self.minor.formatter.set_locs(minor_locs) | ||
| 1079 | + minor_labels = self.minor.formatter.format_ticks(minor_locs) | ||
| 1080 | + for tick, loc, label in zip(minor_ticks, minor_locs, minor_labels): | ||
| 1081 | + tick.update_position(loc) | ||
| 1082 | + tick.set_label1(label) | ||
| 1083 | + tick.set_label2(label) | ||
| 1084 | + ticks = [*major_ticks, *minor_ticks] | ||
| 1085 | + | ||
| 1086 | + view_low, view_high = self.get_view_interval() | ||
| 1087 | + if view_low > view_high: | ||
| 1088 | + view_low, view_high = view_high, view_low | ||
| 1089 | + | ||
| 1090 | + if self._smart_bounds and ticks: | ||
| 1071 | 1091 | # handle inverted limits | |
| 1072 | - view_low, view_high = sorted(interval) | ||
| 1073 | 1092 | data_low, data_high = sorted(self.get_data_interval()) | |
| 1074 | - locs = np.sort([ti[1] for ti in tick_tups]) | ||
| 1093 | + locs = np.sort([tick.get_loc() for tick in ticks]) | ||
| 1075 | 1094 | if data_low <= view_low: | |
| 1076 | 1095 | # data extends beyond view, take view as limit | |
| 1077 | 1096 | ilow = view_low | |
@@ -1096,33 +1115,21 @@ def _update_ticks(self, renderer): | |||
| 1096 | 1115 | else: | |
| 1097 | 1116 | # No ticks (why not?), take last tick | |
| 1098 | 1117 | ihigh = locs[-1] | |
| 1099 | - tick_tups = [ti for ti in tick_tups if ilow <= ti[1] <= ihigh] | ||
| 1118 | + ticks = [tick for tick in ticks if ilow <= tick.get_loc() <= ihigh] | ||
| 1100 | 1119 | ||
| 1101 | - if interval[1] <= interval[0]: | ||
| 1102 | - interval = interval[1], interval[0] | ||
| 1103 | - inter = self.get_transform().transform(interval) | ||
| 1120 | + interval_t = self.get_transform().transform([view_low, view_high]) | ||
| 1104 | 1121 | ||
| 1105 | 1122 | ticks_to_draw = [] | |
| 1106 | - for tick, loc, label in tick_tups: | ||
| 1107 | - # draw each tick if it is in interval. Note the transform | ||
| 1108 | - # to pixel space to take care of log transforms etc. | ||
| 1109 | - # interval_contains has a floating point tolerance. | ||
| 1110 | - if tick is None: | ||
| 1111 | - continue | ||
| 1112 | - # NB: always update labels and position to avoid issues like #9397 | ||
| 1113 | - tick.update_position(loc) | ||
| 1114 | - tick.set_label1(label) | ||
| 1115 | - tick.set_label2(label) | ||
| 1123 | + for tick in ticks: | ||
| 1116 | 1124 | try: | |
| 1117 | - loct = self.get_transform().transform(loc) | ||
| 1125 | + loc_t = self.get_transform().transform(tick.get_loc()) | ||
| 1118 | 1126 | except AssertionError: | |
| 1119 | 1127 | # transforms.transform doesn't allow masked values but | |
| 1120 | 1128 | # some scales might make them, so we need this try/except. | |
| 1121 | - loct = None | ||
| 1122 | - continue | ||
| 1123 | - if not mtransforms._interval_contains_close(inter, loct): | ||
| 1124 | - continue | ||
| 1125 | - ticks_to_draw.append(tick) | ||
| 1129 | + pass | ||
| 1130 | + else: | ||
| 1131 | + if mtransforms._interval_contains_close(interval_t, loc_t): | ||
| 1132 | + ticks_to_draw.append(tick) | ||
| 1126 | 1133 | ||
| 1127 | 1134 | return ticks_to_draw | |
| 1128 | 1135 | ||
@@ -1141,7 +1148,7 @@ def get_tightbbox(self, renderer): | |||
| 1141 | 1148 | if not self.get_visible(): | |
| 1142 | 1149 | return | |
| 1143 | 1150 | ||
| 1144 | - ticks_to_draw = self._update_ticks(renderer) | ||
| 1151 | + ticks_to_draw = self._update_ticks() | ||
| 1145 | 1152 | ||
| 1146 | 1153 | self._update_label_position(renderer) | |
| 1147 | 1154 | ||
@@ -1182,7 +1189,7 @@ def draw(self, renderer, *args, **kwargs): | |||
| 1182 | 1189 | return | |
| 1183 | 1190 | renderer.open_group(__name__) | |
| 1184 | 1191 | ||
| 1185 | - ticks_to_draw = self._update_ticks(renderer) | ||
| 1192 | + ticks_to_draw = self._update_ticks() | ||
| 1186 | 1193 | ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw, | |
| 1187 | 1194 | renderer) | |
| 1188 | 1195 | ||
@@ -1948,7 +1955,7 @@ def _get_tick_boxes_siblings(self, renderer): | |||
| 1948 | 1955 | grp = self.figure._align_xlabel_grp | |
| 1949 | 1956 | # if we want to align labels from other axes: | |
| 1950 | 1957 | for nn, axx in enumerate(grp.get_siblings(self.axes)): | |
| 1951 | - ticks_to_draw = axx.xaxis._update_ticks(renderer) | ||
| 1958 | + ticks_to_draw = axx.xaxis._update_ticks() | ||
| 1952 | 1959 | tlb, tlb2 = axx.xaxis._get_tick_bboxes(ticks_to_draw, renderer) | |
| 1953 | 1960 | bboxes.extend(tlb) | |
| 1954 | 1961 | bboxes2.extend(tlb2) | |
@@ -2262,7 +2269,7 @@ def _get_tick_boxes_siblings(self, renderer): | |||
| 2262 | 2269 | grp = self.figure._align_ylabel_grp | |
| 2263 | 2270 | # if we want to align labels from other axes: | |
| 2264 | 2271 | for axx in grp.get_siblings(self.axes): | |
| 2265 | - ticks_to_draw = axx.yaxis._update_ticks(renderer) | ||
| 2272 | + ticks_to_draw = axx.yaxis._update_ticks() | ||
| 2266 | 2273 | tlb, tlb2 = axx.yaxis._get_tick_bboxes(ticks_to_draw, renderer) | |
| 2267 | 2274 | bboxes.extend(tlb) | |
| 2268 | 2275 | bboxes2.extend(tlb2) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -266,15 +266,15 @@ def test_inverted_cla(): | |||
| 266 | 266 | plt.close(fig) | |
| 267 | 267 | ||
| 268 | 268 | ||
| 269 | - @image_comparison(baseline_images=["minorticks_on_rcParams_both"], | ||
| 270 | - extensions=['png']) | ||
| 271 | - def test_minorticks_on_rcParams_both(): | ||
| 272 | - fig = plt.figure() | ||
| 273 | - matplotlib.rcParams['xtick.minor.visible'] = True | ||
| 274 | - matplotlib.rcParams['ytick.minor.visible'] = True | ||
| 275 | - | ||
| 276 | - plt.plot([0, 1], [0, 1]) | ||
| 277 | - plt.axis([0, 1, 0, 1]) | ||
| 269 | + @check_figures_equal(extensions=["png"]) | ||
| 270 | + def test_minorticks_on_rcParams_both(fig_test, fig_ref): | ||
| 271 | + with matplotlib.rc_context({"xtick.minor.visible": True, | ||
| 272 | + "ytick.minor.visible": True}): | ||
| 273 | + ax_test = fig_test.subplots() | ||
| 274 | + ax_test.plot([0, 1], [0, 1]) | ||
| 275 | + ax_ref = fig_ref.subplots() | ||
| 276 | + ax_ref.plot([0, 1], [0, 1]) | ||
| 277 | + ax_ref.minorticks_on() | ||
| 278 | 278 | ||
| 279 | 279 | ||
| 280 | 280 | @image_comparison(baseline_images=["autoscale_tiny_range"], remove_text=True) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -346,17 +346,15 @@ def test_offset_value(self, left, right, offset): | |||
| 346 | 346 | UserWarning) | |
| 347 | 347 | ax.set_xlim(left, right) | |
| 348 | 348 | assert len(w) == (1 if left == right else 0) | |
| 349 | - # Update ticks. | ||
| 350 | - next(ax.get_xaxis().iter_ticks()) | ||
| 349 | + ax.get_xaxis()._update_ticks() | ||
| 351 | 350 | assert formatter.offset == offset | |
| 352 | 351 | ||
| 353 | 352 | with warnings.catch_warnings(record=True) as w: | |
| 354 | 353 | warnings.filterwarnings('always', 'Attempting to set identical', | |
| 355 | 354 | UserWarning) | |
| 356 | 355 | ax.set_xlim(right, left) | |
| 357 | 356 | assert len(w) == (1 if left == right else 0) | |
| 358 | - # Update ticks. | ||
| 359 | - next(ax.get_xaxis().iter_ticks()) | ||
| 357 | + ax.get_xaxis()._update_ticks() | ||
| 360 | 358 | assert formatter.offset == offset | |
| 361 | 359 | ||
| 362 | 360 | @pytest.mark.parametrize('use_offset', use_offset_data) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -223,22 +223,11 @@ def draw(self, renderer): | |||
| 223 | 223 | self.label._transform = self.axes.transData | |
| 224 | 224 | renderer.open_group('axis3d') | |
| 225 | 225 | ||
| 226 | - # code from XAxis | ||
| 227 | - majorTicks = self.get_major_ticks() | ||
| 228 | - majorLocs = self.major.locator() | ||
| 226 | + ticks = self._update_ticks() | ||
| 229 | 227 | ||
| 230 | 228 | info = self._axinfo | |
| 231 | 229 | index = info['i'] | |
| 232 | 230 | ||
| 233 | - # filter locations here so that no extra grid lines are drawn | ||
| 234 | - locmin, locmax = self.get_view_interval() | ||
| 235 | - if locmin > locmax: | ||
| 236 | - locmin, locmax = locmax, locmin | ||
| 237 | - | ||
| 238 | - # Rudimentary clipping | ||
| 239 | - majorLocs = [loc for loc in majorLocs if locmin <= loc <= locmax] | ||
| 240 | - majorLabels = self.major.formatter.format_ticks(majorLocs) | ||
| 241 | - | ||
| 242 | 231 | mins, maxs, centers, deltas, tc, highs = self._get_coord_info(renderer) | |
| 243 | 232 | ||
| 244 | 233 | # Determine grid lines | |
@@ -259,9 +248,9 @@ def draw(self, renderer): | |||
| 259 | 248 | ||
| 260 | 249 | # Grid points where the planes meet | |
| 261 | 250 | xyz0 = [] | |
| 262 | - for val in majorLocs: | ||
| 251 | + for tick in ticks: | ||
| 263 | 252 | coord = minmax.copy() | |
| 264 | - coord[index] = val | ||
| 253 | + coord[index] = tick.get_loc() | ||
| 265 | 254 | xyz0.append(coord) | |
| 266 | 255 | ||
| 267 | 256 | # Draw labels | |
@@ -373,14 +362,14 @@ def draw(self, renderer): | |||
| 373 | 362 | xyz1 = copy.deepcopy(xyz0) | |
| 374 | 363 | newindex = (index + 1) % 3 | |
| 375 | 364 | newval = get_flip_min_max(xyz1[0], newindex, mins, maxs) | |
| 376 | - for i in range(len(majorLocs)): | ||
| 365 | + for i in range(len(ticks)): | ||
| 377 | 366 | xyz1[i][newindex] = newval | |
| 378 | 367 | ||
| 379 | 368 | # Grid points at end of the other plane | |
| 380 | 369 | xyz2 = copy.deepcopy(xyz0) | |
| 381 | 370 | newindex = (index + 2) % 3 | |
| 382 | 371 | newval = get_flip_min_max(xyz2[0], newindex, mins, maxs) | |
| 383 | - for i in range(len(majorLocs)): | ||
| 372 | + for i in range(len(ticks)): | ||
| 384 | 373 | xyz2[i][newindex] = newval | |
| 385 | 374 | ||
| 386 | 375 | lines = list(zip(xyz1, xyz0, xyz2)) | |
@@ -401,13 +390,11 @@ def draw(self, renderer): | |||
| 401 | 390 | else: | |
| 402 | 391 | ticksign = -1 | |
| 403 | 392 | ||
| 404 | - for tick, loc, label in zip(majorTicks, majorLocs, majorLabels): | ||
| 405 | - if tick is None: | ||
| 406 | - continue | ||
| 393 | + for tick in ticks: | ||
| 407 | 394 | ||
| 408 | 395 | # Get tick line positions | |
| 409 | 396 | pos = copy.copy(edgep1) | |
| 410 | - pos[index] = loc | ||
| 397 | + pos[index] = tick.get_loc() | ||
| 411 | 398 | pos[tickdir] = ( | |
| 412 | 399 | edgep1[tickdir] | |
| 413 | 400 | + info['tick']['outward_factor'] * ticksign * tickdelta) | |
@@ -434,8 +421,6 @@ def draw(self, renderer): | |||
| 434 | 421 | tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly)) | |
| 435 | 422 | tick.tick1line.set_linewidth(info['tick']['linewidth']) | |
| 436 | 423 | tick.tick1line.set_color(info['tick']['color']) | |
| 437 | - tick.set_label1(label) | ||
| 438 | - tick.set_label2(label) | ||
| 439 | 424 | tick.draw(renderer) | |
| 440 | 425 | ||
| 441 | 426 | renderer.close_group('axis3d') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments