|
279 | 279 | fig, ax = plt.subplots()\\
|
280 | 280 | ax.plot(X,Y,color='C1')\\
|
281 | 281 | \\
|
282 |
| - plt.savefig(``figure.pdf'')\\ |
283 |
| - plt.show() } |
| 282 | + fig.savefig(``figure.pdf'')\\ |
| 283 | + fig.show() } |
284 | 284 | \end{myboxed}
|
285 | 285 | \vspace{\fill}
|
286 | 286 |
|
|
713 | 713 | ax.\textbf{tick\_params}(width=10, …)\\
|
714 | 714 | ax.\textbf{set\_axis\_[on|off]}()\\
|
715 | 715 | \\
|
716 |
| - plt.\textbf{tight\_layout}()\\ |
| 716 | + ax.\textbf{tight\_layout}()\\ |
717 | 717 | plt.\textbf{gcf}(), plt.\textbf{gca}()\\
|
718 | 718 | mpl.\textbf{rc}('axes', linewidth=1, …)\\
|
719 | 719 | fig.patch.\textbf{set\_alpha}(0)\\
|
|
781 | 781 | %
|
782 | 782 | \begin{myboxed}{Extent \& origin \hfill
|
783 | 783 | \API{https://matplotlib.org/tutorials/intermediate/imshow_extent.html} }
|
784 |
| - plt.\textbf{imshow}( extent=…, origin=… )\\ |
| 784 | + ax.\textbf{imshow}( extent=…, origin=… )\\ |
785 | 785 |
|
786 | 786 | \includegraphics[width=\columnwidth]{extents.pdf}
|
787 | 787 | \end{myboxed}
|
|
790 | 790 | %
|
791 | 791 | \begin{myboxed}{Text alignments \hfill
|
792 | 792 | \API{https://matplotlib.org/tutorials/text/text_props.html} }
|
793 |
| - plt.\textbf{text}( …, ha=… , va=…, … )\\ |
| 793 | + ax.\textbf{text}( …, ha=… , va=…, … )\\ |
794 | 794 |
|
795 | 795 | \includegraphics[width=\columnwidth]{text-alignments.pdf}
|
796 | 796 | \end{myboxed}
|
|
799 | 799 | %
|
800 | 800 | \begin{myboxed}{Text parameters \hfill
|
801 | 801 | \API{https://matplotlib.org/tutorials/text/text_props.html}}
|
802 |
| - plt.\textbf{text}( …, family=… , size=…, weight = …)\\ |
803 |
| - plt.\textbf{text}( …, fontproperties = … )\\ |
| 802 | + ax.\textbf{text}( …, family=… , size=…, weight = …)\\ |
| 803 | + ax.\textbf{text}( …, fontproperties = … )\\ |
804 | 804 |
|
805 | 805 | \includegraphics[width=\columnwidth]{fonts.pdf}
|
806 | 806 | \end{myboxed}
|
|
916 | 916 |
|
917 | 917 | \begin{myboxed}{Legend placement}
|
918 | 918 | \includegraphics[width=\columnwidth]{legend-placement.pdf}
|
919 |
| - plt.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\ |
| 919 | + ax.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\ |
920 | 920 | \begin{tabular}{@{}p{0.33\columnwidth}
|
921 | 921 | p{0.33\columnwidth}
|
922 | 922 | p{0.33\columnwidth}@{}}
|
|
961 | 961 | \textbf{… resize a figure?}\\
|
962 | 962 | \hspace*{2.5mm}~$\rightarrow$ fig.set\_size\_inches(w,h)\\
|
963 | 963 | \textbf{… save a figure?}\\
|
964 |
| - \hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf")\\ |
| 964 | + \hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf")\\ |
965 | 965 | \textbf{… save a transparent figure?}\\
|
966 |
| - \hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf", transparent=True)\\ |
| 966 | + \hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf", transparent=True)\\ |
967 | 967 | \textbf{… clear a figure?}\\
|
968 | 968 | \hspace*{2.5mm}~$\rightarrow$ ax.clear()\\
|
969 | 969 | \textbf{… close all figures?}\\
|
|
973 | 973 | \textbf{… remove tick labels ?}\\
|
974 | 974 | \hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticklabels([])\\
|
975 | 975 | \textbf{… rotate tick labels ?}\\
|
976 |
| - \hspace*{2.5mm}~$\rightarrow$ plt.[xy]ticks(rotation=90)\\ |
| 976 | + \hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticks(rotation=90)\\ |
977 | 977 | \textbf{… hide top spine?}\\
|
978 | 978 | \hspace*{2.5mm}~$\rightarrow$ ax.spines['top'].set\_visible(False)\\
|
979 | 979 | \textbf{… hide legend border?}\\
|
980 |
| - \hspace*{2.5mm}~$\rightarrow$ plt.legend(frameon=False)\\ |
| 980 | + \hspace*{2.5mm}~$\rightarrow$ ax.legend(frameon=False)\\ |
981 | 981 | \textbf{… show error as shaded region?}\\
|
982 | 982 | \hspace*{2.5mm}~$\rightarrow$ ax.fill\_between(X, Y+error, Y-error)\\
|
983 | 983 | \textbf{… draw a rectangle?}\\
|
|
997 | 997 | \textbf{… get a discrete colormap?}\\
|
998 | 998 | \hspace*{2.5mm}~$\rightarrow$ plt.get\_cmap(``viridis'', 10)\\
|
999 | 999 | \textbf{… show a figure for one second?}\\
|
1000 |
| - \hspace*{2.5mm}~$\rightarrow$ plt.show(block=False), time.sleep(1) |
| 1000 | + \hspace*{2.5mm}~$\rightarrow$ fig.show(block=False), time.sleep(1) |
1001 | 1001 | \end{myboxed}
|
1002 | 1002 | %
|
1003 | 1003 | \vspace{\fill}
|
|
0 commit comments