Matplotlib Tutorial (2021): For Physicists, Engineers, and Mathematicians
Video Statistics and Information
Channel: Mr. P Solver
Views: 9,876
Rating: undefined out of 5
Keywords: python, numpy, matplotlib, plotting, tutorial, python tutorial, python tutorial 2021, matplotlib tutorial 2021, physics, how to plot in python, how to make graph in python, python physics, scipy, sympy, how to, differential equation, calculus, engineering, plotly, 3d plot, 3d plot python, python animation, python gif, how to make gif in python, gif in python
Id: cTJBJH8hacc
Channel Id: undefined
Length: 47min 59sec (2879 seconds)
Published: Mon Jun 28 2021
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
Matplotlib is really useful, but I do get annoyed by those little inconsistencies. If I'm doing a simple plot and want to label my x-axis, I just use plt.xlabel('Something'). But when I want to do subplots, I suddenly have to use ax.set_xlabel('Something'). Same with xlim() and set_xlim(), for example.
There are tons of those things in there that could be streamlined, helping new users - and making it much easier to convert several plots into subplots by just copy pasting.
One of my favourite discoveries with Matplotlib was the ability to export to pgf. That way you can pop them straight into latex docs as vector graphics and be able to change fonts, aspect ratios etc whenever you want without having to replot everything. I belive you need tikz to display them but cant remember off the top of my head.
In this tutorial i discuss how to make line plots, histograms, surface plots, contour plots, and animations that are of sufficient quality to publish. One of the main libraries I use is called SciencePlots which makes the plots have an IEEE style.
Besides from being a plotting tutorial, this is also a tutorial in data representation for lab reports in undergrad. For example, I show how you might plot collected data vs. a fitted curve, and how to make an animation of a surface that represents something like the solution of Laplace's equation.
If you are a physicist and plan on publishing papers, terribly looking ‘94 feelings plot are a de facto standard
One thing I like to do when I have multiple subplots is use
axes=axes.flatten()
so I can loop through each subplot. Then I can put all of the common subplot adjustments in the loop. It can get more complex if you aren't plotting similar graphs in each subplot, but lately that's what I've been doing. For example, something like this.Although I appreciate the fun in learning something new, can you explain what the benefit is to doing this as opposed to using Tikz to plot the figures directly in LaTeX please?
I love how ugly the graphic in the thumbnail is.
A lovely video, very useful with many helpful hints. My largest frustration with matplotlib is in trying to use a Times New Roman font. (It's for publication in a text.) Times New Roman is easy to implement in titles, legends, and so on, but when I use LaTeX in the titles, legends, the Times New Roman is replaced by the default font. Any suggestions will be welcome!
I recently moved to Julia, and it's surprising how much more consistent the plotting interface is (in Plots.jl) -- you can use multiple backends (Plotly, Matplotlib) all without changing your code.