{"id":5602,"date":"2017-01-05T09:54:56","date_gmt":"2017-01-05T09:54:56","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=5602"},"modified":"2022-08-23T12:03:33","modified_gmt":"2022-08-23T12:03:33","slug":"numpy-and-matplotlib","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=5602","title":{"rendered":"Python matplotlib"},"content":{"rendered":"<p><a href=\"https:\/\/matplotlib.org\/3.1.1\/tutorials\/intermediate\/tight_layout_guide.html\">Tight Layout guide<\/a><\/p>\n<h3>Advanced plotting<\/h4>\n<p><a href=\"https:\/\/python4astronomers.github.io\/plotting\/advanced.html\">Advanced plotting<\/a><\/p>\n<ul>\n<li>Moving to object-based plotting<\/li>\n<li>Figure size<\/li>\n<li>Placing Axes<\/li>\n<li>Twin axes<\/li>\n<li>Controlling the appearance of plots<\/li>\n<li>rc parameters<\/li>\n<li>Adding a legend<\/li>\n<li>Adding a colorbar<\/li>\n<li>Custom ticks and labels<\/li>\n<li>Artists, Patches, and Lines<\/li>\n<\/ul>\n<h3>stackoverflow<\/h3>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/8209568\/how-do-i-draw-a-grid-onto-a-plot-in-python\/37896687\">How do I draw a grid onto a plot in Python? [closed]<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/33640117\/set-figure-object-to-bounding-box-of-fig-get-tightbbox\">Set figure object to bounding box of fig.get_tightbbox()<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/29809238\/definition-of-matplotlib-pyplot-axes-bbox\">Definition of matplotlib.pyplot.axes.bbox<\/a><\/p>\n<h3>Backend<\/h3>\n<p><a href=\"https:\/\/matplotlib.org\/tutorials\/introductory\/usage.html#backends\">Usage Guide &#8211; Backends<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/39305810\/matplotlib-use-required-before-other-imports-clashes-with-pep8-ignore-or-fix\">matplotlib.use required before other imports clashes with pep8. Ignore or fix?<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nimport matplotlib\r\nmatplotlib.use('GTK3Cairo')  # noqa\r\nimport matplotlib.pyplot as plt\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nTkCairo\r\nGTK3Agg\r\nGTK3Cairo\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nValueError: Unrecognized backend string 'gtk': valid strings are\r\n&#x5B;'GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo',\r\n 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg',\r\n 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']\r\n<\/pre>\n<h3>LaTex<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n$ sudo apt-get install texlive texlive-lang-german texlive-latex-extra \r\n$ sudo apt-get install dvipng\r\n$ sudo apt-get install ghostscript-x\r\n<\/pre>\n<p><a href=\"http:\/\/matplotlib.org\/users\/usetex.html\">Text rendering With LaTeX<\/a><br \/>\n<a href=\"http:\/\/omz-software.com\/pythonista\/matplotlib\/users\/usetex.html\">Text rendering With LaTeX<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/14016217\/how-do-i-write-a-latex-formula-in-the-legend-of-a-plot-using-matplotlib-inside-a\">How do I write a Latex formula in the legend of a plot using Matplotlib inside a .py file?<\/a><br \/>\n<a href=\"https:\/\/matplotlib.org\/stable\/tutorials\/text\/usetex.html\">Text rendering with LaTeX<\/a><br \/>\n<a href=\"https:\/\/matplotlib.org\/stable\/gallery\/text_labels_and_annotations\/tex_demo.html\">Rendering math equations using TeX<\/a><\/p>\n<h4>\\displaystyle<\/h4>\n<p><a href=\"https:\/\/de.sharelatex.com\/learn\/latex\/Display_style_in_math_mode\">Display style in math mode<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\\displaystyle\r\nworks: GTK3Agg\r\ndoesn't work: GTK3Cairo, TkCairo\r\n<\/pre>\n<h3>Convert to PostScript \/ PDF<\/h3>\n<p><a href=\"https:\/\/poppler.freedesktop.org\/\">Poppler<\/a>, a PDF rendering library<br \/>\n<a href=\"http:\/\/www.foolabs.com\/xpdf\/\">Xpdf<\/a>, an open source viewer for Portable Document Format (PDF) files<\/p>\n<p><!-- ------------------------------------------------------------------------- --><\/p>\n<hr\/>\n<h1>Zoom<\/h1>\n<pre class=\"brush: python; title: Lib\/site-packages\/matplotlib\/backends\/backend_qt.py; notranslate\" title=\"Lib\/site-packages\/matplotlib\/backends\/backend_qt.py\">\r\n\r\nclass FigureManagerQT(FigureManagerBase):\r\n    def __init__(self, canvas, num):\r\n        self.window = MainWindow()\r\n        super().__init__(canvas, num)\r\n        self.window.closing.connect(canvas.close_event)\r\n        self.window.closing.connect(self._widgetclosed)\r\n\r\n        image = str(cbook._get_data_path('images\/matplotlib.svg'))\r\n        self.window.setWindowIcon(QtGui.QIcon(image))\r\n\r\n        self.window._destroying = False\r\n\r\n        self.toolbar = self._get_toolbar(self.canvas, self.window)\r\n        self.window.setCentralWidget(self.canvas)\r\n\r\n        # &#x5B;...]\r\n\r\n        if self.toolbar:\r\n            self.window.addToolBar(self.toolbar)\r\n            tbs_height = self.toolbar.sizeHint().height()\r\n\r\n    def _get_toolbar(self, canvas, parent):\r\n        # must be inited after the window, drawingArea and figure\r\n        # attrs are set\r\n        if mpl.rcParams&#x5B;'toolbar'] == 'toolbar2':\r\n            toolbar = NavigationToolbar2QT(canvas, parent, True)\r\n        elif mpl.rcParams&#x5B;'toolbar'] == 'toolmanager':\r\n            toolbar = ToolbarQt(self.toolmanager, self.window)\r\n        else:\r\n            toolbar = None\r\n        return toolbar\r\n\r\nclass NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):\r\n    def __init__(self, canvas, parent, coordinates=True):\r\n        # &#x5B;...]\r\n        for text, tooltip_text, image_file, callback in self.toolitems:\r\n            if text is None:\r\n                self.addSeparator()\r\n            else:\r\n                a = self.addAction(self._icon(image_file + '.png'),\r\n                                   text, getattr(self, callback))\r\n                self._actions&#x5B;callback] = a\r\n                if callback in &#x5B;'zoom', 'pan']:\r\n                    a.setCheckable(True)\r\n                if tooltip_text is not None:\r\n                    a.setToolTip(tooltip_text)\r\n        # &#x5B;...]\r\n<\/pre>\n<table>\n<tr>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/table>\n<pre class=\"brush: python; title: Lib\/site-packages\/matplotlib\/backends\/backend_qt.py; notranslate\" title=\"Lib\/site-packages\/matplotlib\/backends\/backend_qt.py\">\r\n    def drawRectangle(self, rect):\r\n        # Draw the zoom rectangle to the QPainter.  _draw_rect_callback needs\r\n        # to be called at the end of paintEvent.\r\n\r\n\r\n# Toolbar Zoom Button Click\r\nclass NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):\r\n    &#x5B;...]\r\n    def zoom(self, *args):\r\n        super().zoom(*args)\r\n        self._update_buttons_checked()\r\n    &#x5B;...]\r\n<\/pre>\n<table>\n<tr>\n<td><a href=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2017\/01\/drawRectangle.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.bachi.net\/wp-content\/uploads\/2017\/01\/drawRectangle-300x238.png\" alt=\"\" width=\"300\" height=\"238\" class=\"alignleft size-medium wp-image-13175\" srcset=\"https:\/\/blog.bachi.net\/wp-content\/uploads\/2017\/01\/drawRectangle-300x238.png 300w, https:\/\/blog.bachi.net\/wp-content\/uploads\/2017\/01\/drawRectangle.png 317w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<\/tr>\n<\/table>\n<p><!-- ------------------------------------------------------------------------- --><\/p>\n<hr\/>\n<h1>Tooltip \/ Annotation<\/h1>\n<p><a href=\"https:\/\/towardsdatascience.com\/tooltips-with-pythons-matplotlib-dcd8db758846\">Tooltips with Python\u2019s Matplotlib<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/7908636\/how-to-add-hovering-annotations-to-a-plot\">How to add hovering annotations to a plot<\/a><\/p>\n<p><!-- ------------------------------------------------------------------------- --><\/p>\n<hr\/>\n<h1>Pick Event<\/h1>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/45342912\/click-data-on-off-in-legend-python-scatterplot\/46550271#46550271\">click data on\/off in legend python scatterplot<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/68643549\/is-it-possible-to-use-matplotlib-legend-picker-selecting-legend-text-area-not-le\">Is it possible to use matplotlib legend picker selecting legend text area not legend line?<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/7969352\/matplotlib-interactively-select-points-or-locations\">matplotlib &#8212; interactively select points or locations?<\/a><br \/>\n<a href=\"https:\/\/matplotlib.org\/stable\/gallery\/event_handling\/legend_picking.html\">Legend Picking<\/a><br \/>\n<a href=\"https:\/\/matplotlib.org\/stable\/gallery\/event_handling\/pick_event_demo.html\">Pick Event Demo<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tight Layout guide Advanced plotting Advanced plotting Moving to object-based plotting Figure size Placing Axes Twin axes Controlling the appearance of plots rc parameters Adding a legend Adding a colorbar Custom ticks and labels Artists, Patches, and Lines stackoverflow How do I draw a grid onto a plot in Python? [closed] Set figure object to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5602","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/5602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5602"}],"version-history":[{"count":15,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/5602\/revisions"}],"predecessor-version":[{"id":13348,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/5602\/revisions\/13348"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}