| 739 | |
| 740 | |
| 741 | def PyplotScales(): |
| 742 | import numpy as np |
| 743 | import matplotlib.pyplot as plt |
| 744 | |
| 745 | from matplotlib.ticker import NullFormatter # useful for `logit` scale |
| 746 | |
| 747 | # Fixing random state for reproducibility |
| 748 | np.random.seed(19680801) |
| 749 | |
| 750 | # make up some data in the interval ]0, 1[ |
| 751 | y = np.random.normal(loc=0.5, scale=0.4, size=1000) |
| 752 | y = y[(y > 0) & (y < 1)] |
| 753 | y.sort() |
| 754 | x = np.arange(len(y)) |
| 755 | |
| 756 | # plot with various axes scales |
| 757 | plt.figure(1) |
| 758 | |
| 759 | # linear |
| 760 | plt.subplot(221) |
| 761 | plt.plot(x, y) |
| 762 | plt.yscale('linear') |
| 763 | plt.title('linear') |
| 764 | plt.grid(True) |
| 765 | |
| 766 | # log |
| 767 | plt.subplot(222) |
| 768 | plt.plot(x, y) |
| 769 | plt.yscale('log') |
| 770 | plt.title('log') |
| 771 | plt.grid(True) |
| 772 | |
| 773 | # symmetric log |
| 774 | plt.subplot(223) |
| 775 | plt.plot(x, y - y.mean()) |
| 776 | plt.yscale('symlog', linthreshy=0.01) |
| 777 | plt.title('symlog') |
| 778 | plt.grid(True) |
| 779 | |
| 780 | # logit |
| 781 | plt.subplot(224) |
| 782 | plt.plot(x, y) |
| 783 | plt.yscale('logit') |
| 784 | plt.title('logit') |
| 785 | plt.grid(True) |
| 786 | # Format the minor tick labels of the y-axis into empty strings with |
| 787 | # `NullFormatter`, to avoid cumbering the axis with too many labels. |
| 788 | plt.gca().yaxis.set_minor_formatter(NullFormatter()) |
| 789 | # Adjust the subplot layout, because the logit one may take more space |
| 790 | # than usual, due to y-tick labels like "1 - 10^{-3}" |
| 791 | plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25, |
| 792 | wspace=0.35) |
| 793 | return plt.gcf() |
| 794 | |
| 795 | |
| 796 | def AxesGrid(): |