|
286 | 286 | Y = np.cos(X)\\
|
287 | 287 | \\
|
288 | 288 | fig, ax = plt.subplots()\\
|
289 |
| - ax.plot(X,Y,color='C1')\\ |
| 289 | + ax.plot(X, Y, color='green')\\ |
290 | 290 | \\
|
291 | 291 | fig.savefig(``figure.pdf'')\\
|
292 | 292 | fig.show() }
|
|
303 | 303 | \API{https://matplotlib.org/tutorials/intermediate/gridspec.html} }
|
304 | 304 | \plot{layout-subplot.pdf}{\textbf{subplot[s]}(rows,cols,…)}
|
305 | 305 | {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html}
|
306 |
| - {\ttfamily fig, axs = plt.subplots(3,3)} |
| 306 | + {\ttfamily fig, axs = plt.subplots(3, 3)} |
307 | 307 | {}
|
308 | 308 | \plot{layout-gridspec.pdf}{G = \textbf{gridspec}(rows,cols,…)}
|
309 | 309 | {https://matplotlib.org/stable/api/_as_gen/matplotlib.gridspec.GridSpec.html}
|
|
313 | 313 | {}{}
|
314 | 314 | \plot{layout-divider.pdf}{d=\textbf{make\_axes\_locatable}(ax)}
|
315 | 315 | {https://matplotlib.org/mpl_toolkits/axes_grid/users/axes_divider.html}
|
316 |
| - {\ttfamily ax=d.new\_horizontal('10\%')}{} |
| 316 | + {\ttfamily ax = d.new\_horizontal('10\%')}{} |
317 | 317 | \end{myboxed}
|
318 | 318 | \vspace{\fill}
|
319 | 319 |
|
|
364 | 364 | \optional{bottom},
|
365 | 365 | \optional{align},
|
366 | 366 | \optional{color} }{}
|
367 |
| - \plot{basic-imshow.pdf}{\textbf{imshow}(Z,[cmap],…)} |
| 367 | + \plot{basic-imshow.pdf}{\textbf{imshow}(Z,…)} |
368 | 368 | {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html}
|
369 | 369 | { \mandatory{Z},
|
370 | 370 | \optional{cmap},
|
371 | 371 | \optional{interpolation},
|
372 | 372 | \optional{extent},
|
373 | 373 | \optional{origin} }
|
374 | 374 | {}
|
375 |
| - \plot{basic-contour.pdf}{\textbf{contour[f]}([X],[Y],Z,,…)} |
| 375 | + \plot{basic-contour.pdf}{\textbf{contour[f]}([X],[Y],Z,…)} |
376 | 376 | {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html}
|
377 | 377 | { \optional{X},
|
378 | 378 | \optional{Y},
|
|
401 | 401 | \optional{units},
|
402 | 402 | \optional{angles} }
|
403 | 403 | {}
|
404 |
| - \plot{basic-pie.pdf}{\textbf{pie}(X,[explode],…)} |
| 404 | + \plot{basic-pie.pdf}{\textbf{pie}(X,…)} |
405 | 405 | {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pie.html}
|
406 | 406 | {\mandatory{Z},
|
407 | 407 | \optional{explode},
|
|
420 | 420 | \optional{weight},
|
421 | 421 | \optional{transform} }
|
422 | 422 | {}
|
423 |
| - \plot{basic-fill.pdf}{\textbf{fill[\_between][x]}( … )} |
| 423 | + \plot{basic-fill.pdf}{\textbf{fill[\_between][x]}(…)} |
424 | 424 | {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.fill.html}
|
425 | 425 | {\mandatory{X},
|
426 | 426 | \optional{Y1},
|
|
666 | 666 | {\ttfamily \scriptsize
|
667 | 667 | import matplotlib.animation as mpla\par
|
668 | 668 | ~\par
|
669 |
| - T = np.linspace(0,2*np.pi,100)\par |
| 669 | + T = np.linspace(0, 2*np.pi, 100)\par |
670 | 670 | S = np.sin(T)\par
|
671 | 671 | line, = plt.plot(T, S)\par
|
672 | 672 | def animate(i):\par
|
673 |
| - ~~line.set\_ydata(np.sin(T+i/50))\par |
| 673 | + ~~~~line.set\_ydata(np.sin(T+i/50))\par |
674 | 674 | anim = mpla.FuncAnimation(\par
|
675 |
| - ~~plt.gcf(), animate, interval=5)\par |
| 675 | + ~~~~plt.gcf(), animate, interval=5)\par |
676 | 676 | plt.show()\par
|
677 | 677 | }
|
678 | 678 | \end{myboxed}
|
|
794 | 794 | %
|
795 | 795 | \begin{myboxed}{Text alignments \hfill
|
796 | 796 | \API{https://matplotlib.org/tutorials/text/text_props.html} }
|
797 |
| - ax.\textbf{text}( …, ha=… , va=…, … )\\ |
| 797 | + ax.\textbf{text}( …, ha=… , va=…, …)\\ |
798 | 798 |
|
799 | 799 | \includegraphics[width=\columnwidth]{text-alignments.pdf}
|
800 | 800 | \end{myboxed}
|
|
803 | 803 | %
|
804 | 804 | \begin{myboxed}{Text parameters \hfill
|
805 | 805 | \API{https://matplotlib.org/tutorials/text/text_props.html}}
|
806 |
| - ax.\textbf{text}( …, family=… , size=…, weight = …)\\ |
807 |
| - ax.\textbf{text}( …, fontproperties = … )\\ |
| 806 | + ax.\textbf{text}(…, family=…, size=…, weight=…)\\ |
| 807 | + ax.\textbf{text}(…, fontproperties=…)\\ |
808 | 808 |
|
809 | 809 | \includegraphics[width=\columnwidth]{fonts.pdf}
|
810 | 810 | \end{myboxed}
|
|
963 | 963 | %
|
964 | 964 | \begin{myboxed}{How do I …}
|
965 | 965 | \textbf{… resize a figure?}\\
|
966 |
| - \hspace*{2.5mm}~$\rightarrow$ fig.set\_size\_inches(w,h)\\ |
| 966 | + \hspace*{2.5mm}~$\rightarrow$ fig.set\_size\_inches(w, h)\\ |
967 | 967 | \textbf{… save a figure?}\\
|
968 | 968 | \hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf")\\
|
969 | 969 | \textbf{… save a transparent figure?}\\
|
|
985 | 985 | \textbf{… show error as shaded region?}\\
|
986 | 986 | \hspace*{2.5mm}~$\rightarrow$ ax.fill\_between(X, Y+error, Y-error)\\
|
987 | 987 | \textbf{… draw a rectangle?}\\
|
988 |
| - \hspace*{2.5mm}~$\rightarrow$ ax.add\_patch(plt.Rectangle((0, 0),1,1)\\ |
| 988 | + \hspace*{2.5mm}~$\rightarrow$ ax.add\_patch(plt.Rectangle((0, 0), 1, 1)\\ |
989 | 989 | \textbf{… draw a vertical line?}\\
|
990 | 990 | \hspace*{2.5mm}~$\rightarrow$ ax.axvline(x=0.5)\\
|
991 | 991 | \textbf{… draw outside frame?}\\
|
992 | 992 | \hspace*{2.5mm}~$\rightarrow$ ax.plot(…, clip\_on=False)\\
|
993 | 993 | \textbf{… use transparency?}\\
|
994 | 994 | \hspace*{2.5mm}~$\rightarrow$ ax.plot(…, alpha=0.25)\\
|
995 | 995 | \textbf{… convert an RGB image into a gray image? }\\
|
996 |
| - \hspace*{2.5mm}~$\rightarrow$ gray = 0.2989*R+0.5870*G+0.1140*B\\ |
| 996 | + \hspace*{2.5mm}~$\rightarrow$ gray = 0.2989*R + 0.5870*G + 0.1140*B\\ |
997 | 997 | \textbf{… set figure background color?}\\
|
998 | 998 | \hspace*{2.5mm}~$\rightarrow$ fig.patch.set\_facecolor(``grey'')\\
|
999 | 999 | \textbf{… get a reversed colormap?}\\
|
|
0 commit comments