MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / format_coord

Method format_coord

lib/matplotlib/projections/polar.py:1384–1426  ·  view source on GitHub ↗
(self, theta, r)

Source from the content-addressed store, hash-verified

1382 return self.yaxis.get_gridlines(), self.yaxis.get_ticklabels()
1383
1384 def format_coord(self, theta, r):
1385 # docstring inherited
1386 screen_xy = self.transData.transform((theta, r))
1387 screen_xys = screen_xy + np.stack(
1388 np.meshgrid([-1, 0, 1], [-1, 0, 1])).reshape((2, -1)).T
1389 ts, rs = self.transData.inverted().transform(screen_xys).T
1390 delta_t = abs((ts - theta + np.pi) % (2 * np.pi) - np.pi).max()
1391 delta_t_halfturns = delta_t / np.pi
1392 delta_t_degrees = delta_t_halfturns * 180
1393 delta_r = abs(rs - r).max()
1394 if theta < 0:
1395 theta += 2 * np.pi
1396 theta_halfturns = theta / np.pi
1397 theta_degrees = theta_halfturns * 180
1398
1399 # See ScalarFormatter.format_data_short. For r, use #g-formatting
1400 # (as for linear axes), but for theta, use f-formatting as scientific
1401 # notation doesn't make sense and the trailing dot is ugly.
1402 def format_sig(value, delta, opt, fmt):
1403 # For "f", only count digits after decimal point.
1404 prec = (max(0, -math.floor(math.log10(delta))) if fmt == "f" else
1405 cbook._g_sig_digits(value, delta))
1406 return f"{value:-{opt}.{prec}{fmt}}"
1407
1408 # In case fmt_xdata was not specified, resort to default
1409
1410 if self.fmt_ydata is None:
1411 r_label = format_sig(r, delta_r, "#", "g")
1412 else:
1413 r_label = self.format_ydata(r)
1414
1415 if self.fmt_xdata is None:
1416 return ('\N{GREEK SMALL LETTER THETA}={}\N{GREEK SMALL LETTER PI} '
1417 '({}\N{DEGREE SIGN}), r={}').format(
1418 format_sig(theta_halfturns, delta_t_halfturns, "", "f"),
1419 format_sig(theta_degrees, delta_t_degrees, "", "f"),
1420 r_label
1421 )
1422 else:
1423 return '\N{GREEK SMALL LETTER THETA}={}, r={}'.format(
1424 self.format_xdata(theta),
1425 r_label
1426 )
1427
1428 def get_data_ratio(self):
1429 """

Callers

nothing calls this directly

Calls 5

maxMethod · 0.80
format_ydataMethod · 0.80
format_xdataMethod · 0.80
transformMethod · 0.45
invertedMethod · 0.45

Tested by

no test coverage detected