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)
| 426 | |
| 427 | |
| 428 | def 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]), |
no test coverage detected