MCPcopy Index your code
hub / github.com/plotly/plotly.py / prep_ticks

Function prep_ticks

plotly/matplotlylib/mpltools.py:428–514  ·  view source on GitHub ↗

Prepare axis obj belonging to axes obj. positional arguments: ax - the mpl axes instance index - the index of the axis in `props` ax_type - 'x' or 'y' (for now) props - an mplexporter poperties dictionary

(ax, index, ax_type, props)

Source from the content-addressed store, hash-verified

426
427
428def prep_ticks(ax, index, ax_type, props):
429 """Prepare axis obj belonging to axes obj.
430
431 positional arguments:
432 ax - the mpl axes instance
433 index - the index of the axis in `props`
434 ax_type - 'x' or 'y' (for now)
435 props - an mplexporter poperties dictionary
436
437 """
438 axis_dict = dict()
439 if ax_type == "x":
440 axis = ax.get_xaxis()
441 elif ax_type == "y":
442 axis = ax.get_yaxis()
443 else:
444 return dict() # whoops!
445
446 scale = props["axes"][index]["scale"]
447 if scale == "linear":
448 # get tick location information
449 try:
450 tickvalues = props["axes"][index]["tickvalues"]
451 tick0 = tickvalues[0]
452 dticks = [
453 round(tickvalues[i] - tickvalues[i - 1], 12)
454 for i in range(1, len(tickvalues) - 1)
455 ]
456 if all([dticks[i] == dticks[i - 1] for i in range(1, len(dticks) - 1)]):
457 dtick = tickvalues[1] - tickvalues[0]
458 else:
459 warnings.warn(
460 "'linear' {0}-axis tick spacing not even, "
461 "ignoring mpl tick formatting.".format(ax_type)
462 )
463 raise TypeError
464 except (IndexError, TypeError):
465 axis_dict["nticks"] = props["axes"][index]["nticks"]
466 else:
467 axis_dict["tick0"] = tick0
468 axis_dict["dtick"] = dtick
469 axis_dict["tickmode"] = None
470 elif scale == "log":
471 try:
472 axis_dict["tick0"] = props["axes"][index]["tickvalues"][0]
473 axis_dict["dtick"] = (
474 props["axes"][index]["tickvalues"][1]
475 - props["axes"][index]["tickvalues"][0]
476 )
477 axis_dict["tickmode"] = None
478 except (IndexError, TypeError):
479 axis_dict = dict(nticks=props["axes"][index]["nticks"])
480 base = axis.get_transform().base
481 if base == 10:
482 if ax_type == "x":
483 axis_dict["range"] = [
484 math.log10(props["xlim"][0]),
485 math.log10(props["xlim"][1]),

Callers 1

prep_xy_axisFunction · 0.85

Calls 3

mpl_dates_to_datestringsFunction · 0.85
formatMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected