Skip to content

Commit

Permalink
deploy: 6a90f2d
Browse files Browse the repository at this point in the history
  • Loading branch information
Kislovskiy committed Mar 18, 2024
1 parent 3266282 commit 83257a0
Show file tree
Hide file tree
Showing 14 changed files with 344 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 348017f562e4810afcdfcfbf113ee645
config: 075901f066eab66725909d144cc50a3e
tags: 645f666f9bcd5a90fca523b33c5a78b7
163 changes: 162 additions & 1 deletion _sources/section_1.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ TODO: link to the jupyter notebook.

**Matplotlib Documentation Pointers:**

* https://matplotlib.org/stable/gallery/subplots_axes_and_figures/figure_size_units.html#sphx-glr-gallery-subplots-axes-and-figures-figure-size-units-py
* `Figure size in different units <https://matplotlib.org/stable/gallery/subplots_axes_and_figures/figure_size_units.html#sphx-glr-gallery-subplots-axes-and-figures-figure-size-units-py>`_

* https://matplotlib.org/stable/gallery/text_labels_and_annotations/fonts_demo.html#sphx-glr-gallery-text-labels-and-annotations-fonts-demo-py

Expand Down Expand Up @@ -109,7 +109,168 @@ Axes

* https://matplotlib.org/stable/gallery/axisartist/demo_axisline_style.html#sphx-glr-gallery-axisartist-demo-axisline-style-py

When you create a figure with `plt.figure()`, it is empty.
You need to add axes to it to start plotting.
`plt.subplots()` is another very common way to create a figure with axes in one go.

But there is a catch.
The Figure is the top-level object, but the Axes object is the one that holds the data and almost all visual elements of the plot.
When we plot something, we are actually adding attributes to the Axes object.

But how do I know that?

That's where **debugging** techiniqes come in handy.

One of my favorite tools for exploring objects is the `rich <https://rich.readthedocs.io/en/stable/introduction.html>`_ library.
`Inspect <https://rich.readthedocs.io/en/stable/reference/init.html?highlight=inspect#rich.inspect>`_ function is a fantastic debug aid that can be used to explore objects in Python.
Take a figure object for an example:

>>> from matplotlib import pyplot as plt
>>> from rich import inspect
>>> fig = plt.figure()
>>> inspect(fig)
╭─────────────────────── <class 'matplotlib.figure.Figure'> ────────────────────────╮
│ The top level container for all the plot elements. │
│ │
│ ╭───────────────────────────────────────────────────────────────────────────────╮ │
│ │ <Figure size 1280x960 with 0 Axes> │ │
│ ╰───────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ artists = [] │
│ axes = [] │
│ bbox = <matplotlib.transforms.TransformedBbox object at 0x132cf3a40> │
│ bbox_inches = Bbox([[0.0, 0.0], [6.4, 4.8]]) │
│ canvas = FigureCanvas object 0x132e56b50 wrapping NSView 0x1437bb380 │
│ clipbox = None │
│ dpi = 200.0 │
│ dpi_scale_trans = <matplotlib.transforms.Affine2D object at 0x132e59ca0> │
│ figbbox = <matplotlib.transforms.TransformedBbox object at 0x132cf3a40> │
│ figure = <Figure size 1280x960 with 0 Axes> │
│ frameon = True │
│ images = [] │
│ legends = [] │
│ lines = [] │
│ mouseover = False │
│ number = 2 │
│ patch = <matplotlib.patches.Rectangle object at 0x132e59be0> │
│ patches = [] │
│ stale = False │
│ sticky_edges = _XYPair(x=[], y=[]) │
│ subfigs = [] │
│ subplotpars = <matplotlib.figure.SubplotParams object at 0x132e59b50> │
│ suppressComposite = None │
│ texts = [] │
│ transFigure = <matplotlib.transforms.BboxTransformTo object at 0x132e5b9e0> │
│ transSubfigure = <matplotlib.transforms.BboxTransformTo object at 0x132e5b9e0> │
│ zorder = 0 │
╰───────────────────────────────────────────────────────────────────────────────────╯

Or you could call `inspect` with `methods` set to `True` (`inspect(fig, methods=True)`) to list all the attributes and methods of the object.
The output is parsed and formatted by the `rich` library, which makes it easy to read and understand.

>>> from matplotlib import pyplot as plt
>>> from rich import inspect
>>> fig, ax = plt.subplots()
>>> inspect(ax)
╭──────────────────────────────── <class 'matplotlib.axes._axes.Axes'> ─────────────────────────────────╮
│ An Axes object encapsulates all the elements of an individual (sub-)plot in │
│ a figure. │
│ │
│ ╭───────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ <Axes: > │ │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ artists = <Axes.ArtistList of 0 artists> │
│ axes = <Axes: > │
│ axison = True │
│ bbox = <matplotlib.transforms.TransformedBbox object at 0x1330ce3c0> │
│ callbacks = <matplotlib.cbook.CallbackRegistry object at 0x1330cf8f0> │
│ child_axes = [] │
│ clipbox = None │
│ collections = <Axes.ArtistList of 0 collections> │
│ containers = [] │
│ dataLim = Bbox([[inf, inf], [-inf, -inf]]) │
│ figure = <Figure size 1280x960 with 1 Axes> │
│ fmt_xdata = None │
│ fmt_ydata = None │
│ ignore_existing_data_limits = True │
│ images = <Axes.ArtistList of 0 images> │
│ legend_ = None │
│ lines = <Axes.ArtistList of 0 lines> │
│ mouseover = False │
│ name = 'rectilinear' │
│ patch = <matplotlib.patches.Rectangle object at 0x13309cc80> │
│ patches = <Axes.ArtistList of 0 patches> │
│ spines = <matplotlib.spines.Spines object at 0x1330ce780> │
│ stale = False │
│ sticky_edges = _XYPair(x=[], y=[]) │
│ tables = <Axes.ArtistList of 0 tables> │
│ texts = <Axes.ArtistList of 0 texts> │
│ title = Text(0.5, 1.0, '') │
│ titleOffsetTrans = <matplotlib.transforms.ScaledTranslation object at 0x13309ff80> │
│ transAxes = <matplotlib.transforms.BboxTransformTo object at 0x132d2a570> │
│ transData = <matplotlib.transforms.CompositeGenericTransform object at 0x1330ceb70> │
│ transLimits = <matplotlib.transforms.BboxTransformFrom object at 0x1330ce150> │
│ transScale = <matplotlib.transforms.TransformWrapper object at 0x1330ce810> │
│ use_sticky_edges = True │
│ viewLim = Bbox([[0.0, 0.0], [1.0, 1.0]]) │
│ xaxis = <matplotlib.axis.XAxis object at 0x1330cef00> │
│ yaxis = <matplotlib.axis.YAxis object at 0x1330cd370> │
│ zorder = 0 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────╯

With this you are equipped to start exploring any codebase and understand how it works.
We'll do it with Matplotlib.

TODO: link to the jupyter notebook section2.

Summary
~~~~~~~

We've learned about two most powerful objects in Matplotlib: Figure and Axes.
They are always coming toghether and are the foundation of any plot.

There are two most important things I want you to remember:

First:

.. code-block:: python
from matplotlib import pyplot as plt
import matplotlib
matplotlib.rcParams.update(
{
"font.family": "sans-serif",
"font.sans-serif": "cmr10",
"font.size": 16,
"axes.formatter.use_mathtext": True,
}
)
fig, ax = plt.subplots(figsize=(3, 3), dpi=300)
ax.text(x=0.5, y=0.5, s="Hello World!", ha="center", va="center")
ax.set_xlabel("Hello World!")
fig.savefig("results/hello_world.svg")
plt.show()
Note: that the font should be installed on your system.
One gotcha is that matplotlib stores fonts available on your system in .matplotlib folder in your home directory.
To see the newly installed font, you need to remove the font cache file.

.. code-block:: bash
~ ❯❯❯ la .matplotlib
Permissions Size User Date Modified Name
.rw-r--r--@ 140k kislovskiy 15 Mar 22:11 fontlist-v330.json
Second:

.. code-block:: python
from matplotlib import pyplot as plt
from rich import inspect
fig, ax = plt.subplots()
inspect(ax, methods=True)
2 changes: 1 addition & 1 deletion _static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DOCUMENTATION_OPTIONS = {
VERSION: '0.0.1',
VERSION: '0.1.5',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
6 changes: 3 additions & 3 deletions genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="#" /><link rel="search" title="Search" href="search.html" />

<!-- Generated with Sphinx 7.2.6 and Furo 2024.01.29 --><title>Index - ChartCraftHub 0.0.1 documentation</title>
<!-- Generated with Sphinx 7.2.6 and Furo 2024.01.29 --><title>Index - ChartCraftHub 0.1.5 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=a746c00c" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=135e06be" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=36a5483c" />
Expand Down Expand Up @@ -121,7 +121,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">ChartCraftHub 0.0.1 documentation</div></a>
<a href="index.html"><div class="brand">ChartCraftHub 0.1.5 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
Expand Down Expand Up @@ -238,7 +238,7 @@ <h1 id="index">Index</h1>

</aside>
</div>
</div><script src="_static/documentation_options.js?v=d45e8c67"></script>
</div><script src="_static/documentation_options.js?v=59fadc99"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/scripts/furo.js?v=32e29ea5"></script>
Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="Introduction" href="intro.html" />

<!-- Generated with Sphinx 7.2.6 and Furo 2024.01.29 -->
<title>ChartCraftHub 0.0.1 documentation</title>
<title>ChartCraftHub 0.1.5 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=a746c00c" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=135e06be" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=36a5483c" />
Expand Down Expand Up @@ -123,7 +123,7 @@
</label>
</div>
<div class="header-center">
<a href="#"><div class="brand">ChartCraftHub 0.0.1 documentation</div></a>
<a href="#"><div class="brand">ChartCraftHub 0.1.5 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
Expand Down Expand Up @@ -325,7 +325,7 @@ <h1>About the Autors<a class="headerlink" href="#about-the-autors" title="Link t

</aside>
</div>
</div><script src="_static/documentation_options.js?v=d45e8c67"></script>
</div><script src="_static/documentation_options.js?v=59fadc99"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/scripts/furo.js?v=32e29ea5"></script>
Expand Down
6 changes: 3 additions & 3 deletions intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="Setup" href="setup.html" /><link rel="prev" title="What is Matplotlib?" href="index.html" />

<!-- Generated with Sphinx 7.2.6 and Furo 2024.01.29 -->
<title>Introduction - ChartCraftHub 0.0.1 documentation</title>
<title>Introduction - ChartCraftHub 0.1.5 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=a746c00c" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=135e06be" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=36a5483c" />
Expand Down Expand Up @@ -123,7 +123,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">ChartCraftHub 0.0.1 documentation</div></a>
<a href="index.html"><div class="brand">ChartCraftHub 0.1.5 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
Expand Down Expand Up @@ -268,7 +268,7 @@ <h1>Introduction<a class="headerlink" href="#introduction" title="Link to this h

</aside>
</div>
</div><script src="_static/documentation_options.js?v=d45e8c67"></script>
</div><script src="_static/documentation_options.js?v=59fadc99"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/scripts/furo.js?v=32e29ea5"></script>
Expand Down
6 changes: 3 additions & 3 deletions resources.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="Terminology" href="terminology.html" /><link rel="prev" title="3. Creating Portable Tools: Packaging Your Figure Creation Toolbox" href="section_3.html" />

<!-- Generated with Sphinx 7.2.6 and Furo 2024.01.29 -->
<title>Resources and Tools We Use - ChartCraftHub 0.0.1 documentation</title>
<title>Resources and Tools We Use - ChartCraftHub 0.1.5 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=a746c00c" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=135e06be" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=36a5483c" />
Expand Down Expand Up @@ -123,7 +123,7 @@
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">ChartCraftHub 0.0.1 documentation</div></a>
<a href="index.html"><div class="brand">ChartCraftHub 0.1.5 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
Expand Down Expand Up @@ -401,7 +401,7 @@ <h2>Quotes from books<a class="headerlink" href="#quotes-from-books" title="Link

</aside>
</div>
</div><script src="_static/documentation_options.js?v=d45e8c67"></script>
</div><script src="_static/documentation_options.js?v=59fadc99"></script>
<script src="_static/doctools.js?v=888ff710"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/scripts/furo.js?v=32e29ea5"></script>
Expand Down
Loading

0 comments on commit 83257a0

Please sign in to comment.