{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Tex\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib\nimport matplotlib.pyplot as plt\nfrom matplotlib import rc\nimport numpy as np\n\n# http://matplotlib.org/users/customizing.html\n# matplotlib.rcParams[\"text.latex.unicode\"] = True # latex unicode\nmatplotlib.rcParams[\"font.family\"] = \"serif\"\n# matplotlib.rcParams[\"text.latex.preamble\"] = [r\"\\usepackage{lmodern}\"]\nrc(\"text\", usetex=True)\n\ndef plot_figure(title: str, xLabel: str, yLabel: str, usetex: bool):\n plt.figure(1, figsize=(6.29921, 5)) # create a new figure window\n # ax = plt.axes([0.1, 0.1, 0.8, 0.7])\n t = np.arange(0.0, 1.0 + 0.01, 0.01)\n s = np.cos(2 * 2 * np.pi * t) + 2\n \n plt.plot(t, s) # plot line\n \n plt.xlabel(xLabel) # x axis label\n plt.ylabel(yLabel) # y axis label\n plt.title(title, fontsize=16, color=\"r\") # title\n \n plt.grid(True) # create grid\n \n spaceToBorder = 0.15\n plt.subplots_adjust(\n left=spaceToBorder,\n right=1 - spaceToBorder,\n top=1 - spaceToBorder,\n bottom=spaceToBorder,\n ) # adjust the space to the border of the figure\n \n plt.show() # show the plot\n \n # get current figure\n current_figure = plt.gcf()\n \n # set the keepSizeFixed property of the plot to true:\n # current_figure.canvas.manager.itomUI[\"keepSizeFixed\"] = True\n \n # change the size\n current_figure.set_dpi(120)\n current_figure.set_size_inches(\n 6.29921, 5, forward=True\n ) # 6.29921 inches are 16mm width of a DIN A4 page\n plt.show()\n # plt.savefig(\"matplotlib.png\", format=\"png\")\n\n\nmatplotlib.rcParams[\"text.usetex\"] = False\n# matplotlib.rcParams[\"text.latex.unicode\"] = False\ntitle = \"TeX is Number $\\sum_{n=1}^\\infty \\frac{-e^{i\\pi}}{2^n}$!\"\nxLabel = \"time [s]\"\nyLabel = \"velocity [\\xb0/sec]\"\nplot_figure(title, xLabel, yLabel, False)\n\nmatplotlib.rcParams[\"text.usetex\"] = True\n# matplotlib.rcParams[\"text.latex.unicode\"] = False\ntitle = r\"\\TeX\\ is Number $\\sum\\limits_{n=1}^\\infty \\frac{-e^{i\\pi}}{2^n}$!\"\nxLabel = r\"time [s]\"\nyLabel = r\"\\textit{velocity [\\ensuremath{^\\circ}/sec]}\"\nplot_figure(title, xLabel, yLabel, True)\n\n\nmatplotlib.rcParams[\"text.usetex\"] = True\n# matplotlib.rcParams[\"text.latex.unicode\"] = True\ntitle = r\"\\TeX\\ is Number $\\sum\\limits_{n=1}^\\infty \\frac{-e^{i\\pi}}{2^n}$!\"\nxLabel = r\"\\textbf{time [s]}\"\nyLabel = u\"\\\\textit{velocity [\\xb0/sec]}\"\nplot_figure(title, xLabel, yLabel, True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }