|
217 | 217 | \newenvironment{myboxed}[1]
|
218 | 218 | {\begin{mdframed}[linecolor=black,
|
219 | 219 | backgroundcolor=white,
|
220 |
| - outerlinewidth=.1pt, |
221 |
| - roundcorner=0.25em, |
| 220 | + outerlinewidth=0.25pt, |
| 221 | + %roundcorner=0.25em, |
222 | 222 | innertopmargin=1ex,
|
| 223 | + topline=true, |
| 224 | + rightline=true, |
| 225 | + leftline=true, |
| 226 | + bottomline=true, |
| 227 | + linecolor=black!10, |
223 | 228 | frametitleaboveskip=0.5em,
|
224 | 229 | frametitlebelowskip=0.5em,
|
225 | 230 | innerbottommargin=.5\baselineskip,
|
226 |
| - innerrightmargin=.5em, innerleftmargin=.5em, |
| 231 | + innerrightmargin=.5em, |
| 232 | + innerleftmargin=.5em, |
227 | 233 | %userdefinedwidth=1\textwidth,
|
228 |
| - frametitle={\sffamily \textbf{#1}}, |
| 234 | + frametitle={\scshape \bfseries \sffamily #1}, |
| 235 | + % frametitlerule=true, |
| 236 | + %frametitlerulecolor=red, |
229 | 237 | frametitlebackgroundcolor=black!10,
|
230 | 238 | frametitlerulewidth=2pt]}
|
231 | 239 | {\end{mdframed}}
|
|
876 | 884 | \end{tabular}
|
877 | 885 | \end{myboxed}
|
878 | 886 |
|
| 887 | + |
| 888 | + |
879 | 889 | \begin{myboxed}{Color names}
|
880 | 890 | \includegraphics[width=\columnwidth]{colornames.pdf}
|
881 | 891 | \end{myboxed}
|
882 | 892 | %
|
883 | 893 | \vspace{\fill}
|
884 | 894 | %
|
| 895 | + \begin{myboxed}{Image interpolation} |
| 896 | + plt.\textbf{imshow}(…, interpolation=…)\\ |
| 897 | + plt.\textbf{contour[f]}(…, interpolation=…)\\ |
| 898 | + \includegraphics[width=\columnwidth]{interpolations.pdf} |
| 899 | + \end{myboxed} |
| 900 | + |
| 901 | + |
885 | 902 | \begin{myboxed}{Legend placement}
|
886 | 903 | \includegraphics[width=\columnwidth]{legend-placement.pdf}
|
887 | 904 | plt.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\
|
|
903 | 920 | G: lower left / (1.1,.1) & H: left / (1.1,.5)\\
|
904 | 921 | I: upper left / (1.1,.9) & J: lower right / (.9,1.1)\\
|
905 | 922 | K: lower center / (.5,1.1) & L: lower left / (.1,1.1)
|
906 |
| - \end{tabular} |
907 |
| - |
| 923 | + \end{tabular} |
908 | 924 | \end{myboxed}
|
909 |
| - % |
910 |
| - \vspace{\fill} |
| 925 | + |
| 926 | + \vfill\null \columnbreak |
| 927 | + |
911 | 928 | %
|
912 | 929 | \begin{myboxed}{How do I …}
|
913 | 930 | \textbf{… resize a figure?}\\
|
914 | 931 | \hspace*{2.5mm}~$\rightarrow$ fig.set\_size\_inches(w,h)\\
|
915 | 932 | \textbf{… save a figure?}\\
|
916 | 933 | \hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf")\\
|
| 934 | + \textbf{… save a transparent figure?}\\ |
| 935 | + \hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf", transparent=True)\\ |
917 | 936 | \textbf{… clear a figure?}\\
|
918 | 937 | \hspace*{2.5mm}~$\rightarrow$ ax.clear()\\
|
919 | 938 | \textbf{… close all figures?}\\
|
920 |
| - \hspace*{2.5mm}~$\rightarrow$ plt.close("all") |
| 939 | + \hspace*{2.5mm}~$\rightarrow$ plt.close("all")\\ |
| 940 | + \textbf{… remove ticks?}\\ |
| 941 | + \hspace*{2.5mm}~$\rightarrow$ ax.set\_xticks([])\\ |
| 942 | + \textbf{… remove tick labels ?}\\ |
| 943 | + \hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticklabels([])\\ |
| 944 | + \textbf{… hide top spine?}\\ |
| 945 | + \hspace*{2.5mm}~$\rightarrow$ ax.spines['top'].set\_visible(False)\\ |
| 946 | + \textbf{… hide legend border?}\\ |
| 947 | + \hspace*{2.5mm}~$\rightarrow$ plt.legend(frameon=False)\\ |
| 948 | + \textbf{… show error as shaded region?}\\ |
| 949 | + \hspace*{2.5mm}~$\rightarrow$ ax.fill\_between(X, Y+error, Y-error)\\ |
| 950 | + \textbf{… draw a rectangle?}\\ |
| 951 | + \hspace*{2.5mm}~$\rightarrow$ ax.add\_patch(plt.Rectangle((0, 0),1,1)\\ |
| 952 | + \textbf{… draw outside frame?}\\ |
| 953 | + \hspace*{2.5mm}~$\rightarrow$ ax.plot(…, clip\_on=False)\\ |
| 954 | + \textbf{… use transparency?}\\ |
| 955 | + \hspace*{2.5mm}~$\rightarrow$ ax.plot(…, alpha=0.25)\\ |
| 956 | + \textbf{… set figure background color?}\\ |
| 957 | + \hspace*{2.5mm}~$\rightarrow$ fig.patch.set\_facecolor(``grey'')\\ |
| 958 | + \textbf{… get a reversed colormap?}\\ |
| 959 | + \hspace*{2.5mm}~$\rightarrow$ plt.get\_cmap(``viridis\_r'')\\ |
| 960 | + \textbf{… get a discrete colormap?}\\ |
| 961 | + \hspace*{2.5mm}~$\rightarrow$ plt.get\_cmap(``viridis'', 10) |
| 962 | +%% \textbf{… show a figure for one second?}\\ |
| 963 | +%% \hspace*{2.5mm}~$\rightarrow$ plt.show(block=False), time.sleep(1) |
921 | 964 | \end{myboxed}
|
922 |
| - |
| 965 | + % |
| 966 | + \vspace{\fill} |
| 967 | + % |
923 | 968 | \begin{myboxed}{Performance tips}
|
924 | 969 | {\ttfamily \fontsize{6pt}{7pt}\selectfont
|
925 | 970 | \textcolor{red}{ax.scatter(X, Y) \hfill slow}\\
|
|
933 | 978 | S = [None]*len(X)\\
|
934 | 979 | X = [v for t in zip(X0,X1,S) for v in t]\\
|
935 | 980 | Y = [v for t in zip(Y0,Y1,S) for v in t]\\
|
936 |
| - plt.plot(X,Y) |
937 |
| -} |
| 981 | + plt.plot(X,Y)} |
| 982 | + \end{myboxed} |
| 983 | + % |
| 984 | + \vspace{\fill} |
| 985 | + % |
| 986 | + \begin{myboxed}{Beyond Matplotlib} |
| 987 | + \href{https://seaborn.pydata.org/}{\textbf{Seaborn}}: Statistical Data Visualization\\ |
| 988 | + \href{https://scitools.org.uk/cartopy/docs/latest/}{\textbf{Cartopy}}: Geospatial Data Processing\\ |
| 989 | + \href{https://yt-project.org/doc/index.html}{\textbf{yt}}: Volumetric data Visualization\\ |
| 990 | + \href{https://mpld3.github.io}{\textbf{mpld3}}: Bringing Matplotlib to the browser\\ |
| 991 | + \href{https://datashader.org/}{\textbf{Datashader}}: Large data processing pipeline\\ |
| 992 | + \href{https://plotnine.readthedocs.io/en/latest/}{\textbf{plotnine}}: A Grammar of Graphics for Python |
938 | 993 | \end{myboxed}
|
939 | 994 |
|
940 | 995 | \end{multicols*}
|
|
0 commit comments