\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{DarioPittera (aggialavura)} \pdfinfo{ /Title (python-matplotlib.pdf) /Creator (Cheatography) /Author (DarioPittera (aggialavura)) /Subject (Python - Matplotlib Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{EB65EB} \definecolor{LightBackground}{HTML}{FCEBFC} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Python - Matplotlib Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{DarioPittera (aggialavura)} via \textcolor{DarkBackground}{\uline{cheatography.com/83764/cs/19841/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}DarioPittera (aggialavura) \\ \uline{cheatography.com/aggialavura} \\ \uline{\seqsplit{www}.dariopittera.com} \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 14th June, 2019.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{TO START}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{conda install matplotlib \newline import matplotlib.pyplot as plt \newline \newline \# to print graphs in notebooks \newline \%matplotlib inline} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{BASICS}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{FUNCTIONAL METHOD \{\{ac\}\}}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{plt.plot(x,y)}} & simple line plot \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} -plt.xlabel('str') & set x label \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} -plt.ylabel('str') & set y label \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} -plt.title('str') & set title \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} {\bf{plt.show()}} & show plot \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} {\bf{plt.subplot(r,c,1)* }}\{\{nl\}\}plt.plot(x, y)\{\{nl\}\}{\bf{plt.subplot(r,c,2)}}\{\{nl\}\}plt.plot(y, x, 'g*-') & create multiplots \tn % Row Count 11 (+ 5) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{OBJECT ORIENTED METHOD }} (more control)\{\{ac\}\}} \tn % Row Count 12 (+ 1) % Row 8 \SetRowColor{LightBackground} {\bf{fig = plt.figure()}}\{\{nl\}\}{\bf{ax = fig.add\_axes({[}0,0,1,1{]})}}\{\{nobreak\}\}\{\{nl\}\}ax.plot(x, y, 'b')\{\{nl\}\}ax.set\_xlabel(''str)\{\{nl\}\}ax.set\_ylabel('str')\{\{nl\}\}ax.set\_title(''str) & create canvas\{\{nl\}\}create axes*\{\{nl\}\}create plot\{\{nl\}\}set x label\{\{nl\}\}set y label\{\{nl\}\}set title \tn % Row Count 21 (+ 9) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{** add more axis to have more figures} \tn % Row Count 22 (+ 1) % Row 10 \SetRowColor{LightBackground} {\bf{fig, ax = plt.subplots(r,c)* }}\{\{nl\}\}axes{[}0{]}.plot(x,y)\{\{nl\}\}axes{[}1{]}.plot(x,y)\{\{nl\}\}axes{[}0{]}.set\_title('str')\{\{nl\}\}axes{[}1{]}.set\_title(''str) & subplots \{\{nobreak\}\}\{\{nl\}\}create pl ax1 \{\{nl\}\} create pl ax2\{\{nl\}\}set plot 1 title\{\{nl\}\}set plot 2 title \tn % Row Count 29 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{subplot()}} command requires to specify the number of row and column we want to print the plots, and the third parameter specify what of the graph we are going to handle. \newline {\bf{axes}}: ({[}left, bottom, width, height{]}) \newline {\bf{fig, axes}} allow you to auto-manage axis, you don't have to create them. Axes, now, will be an array of axis.We could use {\bf{for}} loop to populate labels on axis.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{SIZE, SAVE, LEGEND}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{plt.tight\_layout()}} & avoid overlap \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} plt.fig(figsize=(x,x)) & set figuresize \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} plt.fig(figsize=(x,x), dpi=x) & set dpi \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{fig.savefig("name.png")}} & save figure \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} fig.savefig("name", dpi=200) & ..and set dpi \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} ax.plot(x, y, label="str") & set legend \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{ax.legend()}} & show legend \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} ax.legend(loc=0)\{\{nl\}\}ax.legend(loc=1)\{\{nl\}\} ax.legend(loc=2)\{\{nl\}\} ax.legend(loc=3)\{\{nl\}\} ax.legend(loc=4)\{\{nl\}\} & best\{\{nl\}\}upper right\{\{nl\}\}upper left \{\{nl\}\}lower left \{\{nl\}\}lower right \tn % Row Count 19 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{subplot()}} command requires to specify the number of row and column we want to print the plots, and the third parameter specify what of the graph we are going to handle. \newline {\bf{axes}}: ({[}left, bottom, width, height{]}) \newline {\bf{fig, axes}} allow you to auto-manage axis, you don't have to create them. Axes, now, will be an array of axis.We could use {\bf{for}} loop to populate labels on axis.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{COLORS, LINEWIDTHS, LINETYPES}} \tn % Row 0 \SetRowColor{LightBackground} fig = plt.figure()\{\{nl\}\}ax = fig.add\_axes({[}0,0,1,1{]})\{\{nl\}\}ax.plot(x,y\{\{nl\}\}color='\#xxxxxx', \{\{nl\}\}lw=x, \{\{nl\}\}alpha=x,\{\{nl\}\}ls='',\{\{nl\}\}marker='',\{\{nl\}\}markersize=x,\{\{nl\}\}markerfacecolor='',\{\{nl\}\}markeredgecolor='',\{\{nl\}\}markeredgewidth=x) & -{}-{}-{}-\{\{nl\}\}-{}-{}-{}-\{\{nl\}\}-{}-{}-{}-\{\{nl\}\}set color\{\{nl\}\}set linewidth\{\{nl\}\}set alpha\{\{nl\}\}set linestyle\{\{nl\}\}set markertype\{\{nl\}\}set marker size\{\{nl\}\}set mark color\{\{nl\}\}set external col\{\{nl\}\} set marker wdt \tn % Row Count 12 (+ 12) % Row 1 \SetRowColor{white} {\bf{ax.set\_xlim({[}0,1{]})}} & set x axes limit \tn % Row Count 14 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{ax.set\_ylim({[}0,1{]})}} & set y axes limit \tn % Row Count 16 (+ 2) % Row 3 \SetRowColor{white} ax.plot(x, y, 'r-{}-') & MATLAB style \tn % Row Count 17 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}