Matplotlib
matplotlib.org
matplotlib.org
Previous HN discussions:
https://news.ycombinator.com/item?id=35645464 (97 comments)
https://news.ycombinator.com/item?id=28304781 (91 comments)
import matplotlib
theme = {'axes.grid': True,
'grid.linestyle': '--',
'legend.framealpha': 1,
'legend.facecolor': 'white',
'legend.shadow': True,
'legend.fontsize': 14,
'legend.title_fontsize': 16,
'xtick.labelsize': 14,
'ytick.labelsize': 14,
'axes.labelsize': 16,
'axes.titlesize': 20,
'figure.dpi': 100}
matplotlib.rcParams.update(theme)No, it very much isn't. The second and third colors, the orange and the green, look extremely similar to protanopes (red deficiency). Fortunately, there's a plan to fix this for Matplotlib 4.0.
1. the pyplot API (the old one, that is designed to mimic MATLAB - it has functions like plot() and xlabel()).
2. The Axes API - fig, ax = plt.subplots(); then call ax.plot(), ax.set_xlabel() and so on
One should always prefer the Axes way of doing it, it's refactorable and uses less hidden global state.
i wish the axes api didn't exist
I fully agree, but half the time you're looking up how to do something, you find methods documented using the other approach, with slightly different method names that don't even have an alias in the axes API. In fact those are usually the ones you find, because people answering SO questions seem to prefer the brevity.
MATLAB's plotting is not the best, but it's familiar to MATLAB legacy folks, who made up many of the early folks who moved over to Numpy, Matplotlib, SciPy. It was a bridge.
Now I’m thinking there must be many more libraries that are now “in reach” for me for casual use which weren’t just a few weeks ago.
Unfortunately it's missing quite a few specialized plots from matplotlib, in particular the popular histogram plot is strangely difficult to draw.
The name and API come from MATLAB, and once you realize that it makes more sense. It was originally meant to replicate the plotting functionality in python to be familiar to MATLAB users. IMO this is what makes it feel non-pythonic, but it was never really a python API in the first place.
Between matplotlib and pandas I believe we have a sufficient explanation as to how python became the language of choice for data analysis.
Don't get me wrong matplotlib still gives the best looking publication-ready plots (people mentioned bokeh, which is great for interactive plots on the web, but completely unsuitable for creating plots for pdf articles). I just sometimes wish less tweaking was required.
I found proplot: https://proplot.readthedocs.io/en/stable/ is a nice wrapper around matplotlib that alleviates quite a few issues.
This looks like a really nice explainer https://dev.to/skotaro/artist-in-matplotlib---something-i-wa...
However, examples from pgfplots and matplotlib should be considered in a paper, together with the effort in preparing and revising the figures.