Add materials for Python Plotting With Matplotlib (Guide) - #845
Open
realpython-bot wants to merge 1 commit into
Open
realpython-bot wants to merge 1 commit into
realpython-bot wants to merge 1 commit into
Conversation
New companion-code folder for a tutorial that never had one. The tutorial's REPL examples are grouped into one runnable script per section, with print() where seeing the output is the point. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
A brand-new folder for a tutorial that has never had companion code.
python-matplotlib-guide/did not exist before this branch, so this needs an editorial eye as well as a code review — nothing here is a diff against a previously reviewed baseline.Source of truth: the updated draft, not the live article — https://realpython.com/pbjt/blog/post/2331/change/
Maintenance card: https://trello.com/c/5rsIxkMx
How it maps to the article
The tutorial is 100% REPL (
pycon) blocks — it names no scripts at all. Following the house pattern already used inpython-statistics/, each section's REPL sequence became one runnable script, in the article's order and with the article's variable names, withprint()added where seeing the output is the point.object_hierarchy.pysubplots_notation.pyplt.subplots()Notationgridspec_housing.pyplt.subplots()Notation — thesubplot2grid()/ California housing examples (split out because it downloads data)figures_behind_the_scenes.pyimshow_and_matshow.pyimshow()andmatshow()plotting_in_pandas.pyappendix_a_configuration.pyappendix_b_interactive_mode.pyPlus
README.mdin the repo's house form andrequirements.txt.Two of the tutorial's blocks are deliberately not shipped, because there is nothing for a reader to run: the one-line canonical imports in "Pylab: What Is It, and Should I Use It?", and the abridged excerpt of matplotlib's own
pyplot.pysource in "Stateful Versus Stateless Approaches". The README says so explicitly.No examples were invented and no code was "improved". The only deviations from the article's literal text are house style (double quotes, 79 columns,
ruff format) and one lint-forced change: the article writesfig = plt.figure(figsize=(12, 8))in the gridspec example but never usesfig, which tripsF841, so the binding is dropped with a comment pointing that out.dependenciesfield is stale — please look at thisThe draft's
dependenciesfield still reads:Those pins are not what the draft's own output was produced with, and they cannot be installed at all today (uv has no Python 3.6 interpreter available, and
pandas==0.22.0fails to even resolve: itspytz (>=2011k)requirement is not a parseable version). I tried them first and recorded the failure rather than skipping the step.The draft's shown output pins the real versions unambiguously:
array([[<Axes: >, ...]], dtype=object)— the<Axes: >repr is matplotlib ≥ 3.6<class 'matplotlib.axes._axes.Axes'>— the private-module path is matplotlib ≥ 3.7plt.style.availableincludingpetroff6,petroff8, andpetroff10— matplotlib ≥ 3.11.squeeze("columns")onread_csv— modern pandasSo
requirements.txthere pins matplotlib==3.11.2, numpy==2.5.3, pandas==3.0.5 — the current releases, which are also exactly what the siblingpython-statistics/folder pins. Every piece of output in the article reproduces byte for byte on these. CMS is read-only for this run, so thedependenciesfield on post 2331 still needs a human to correct it — that is the one follow-up this PR can't do itself.How it was verified
MPLBACKEND=Agg. All exit 0, with zero warnings on stderr.<class 'matplotlib.figure.Figure'>,<class 'matplotlib.axis.YTick'>,<class 'matplotlib.axes._axes.Axes'>,(True, True),<class 'numpy.ndarray'>, thearray([[<Axes: >, ...]], dtype=object)repr,(2, 2), the fullnolabelsdict,[1, 2],[<Figure size 640x480 with 1 Axes>, <Figure size 640x480 with 1 Axes>],[],Trueforid(plt.gca()) == id(ax), the sevenrc*attributes, and the complete 28-entryplt.style.availablelist.matshow()heatmap renders the expected X-pattern with the white in-cell numbers and themake_axes_locatablecolorbar).requirements.txtpins:uvx ruff@0.14.1 format --check python-matplotlib-guide→ 8 files already formatted;uvx ruff@0.14.1 check python-matplotlib-guide→ All checks passed!Two outputs that legitimately cannot match, both documented in the README
figures_behind_the_scenes.pyprintsid()values — memory addresses, so the numbers differ from the article's4525567840. Only the comparisons between them are meaningful, and those match.appendix_b_interactive_mode.pyfirst printsFalsewhere the article showsTrue. The article is in an interactive session; matplotlib starts a script with interactive mode off. Theplt.ioff()toggle the section is actually about behaves identically.Nothing was skipped
Both network-dependent scripts really ran in CI-like conditions here:
gridspec_housing.pydownloaded the California housing archive from figshare, andplotting_in_pandas.pydownloaded the VIX series from FRED. No GUI, server, or paid API key is needed by anything in this folder. Note for reviewers that these two are live-network scripts and will fail offline — the README calls that out.🤖 Generated with Claude Code