Teach you to draw cool professional illustrations with Python

Python’s plotting module matplotlib: python plotting is highly recommended. The drawn picture is really high-end and high-grade, low-key luxury and connotation~ It is suitable for all kinds of drawings from 2D to 3D, from scalar to vector. It can be saved in various formats from eps, pdf to svg, png, jpg.

And the drawing functions of Matplotlib basically have the same names as the drawing functions of Matlab, and the learning cost of migration is relatively low. Open source and free. As shown in the picture (the picture in the title description is at the end): (The following pictures are all quoted from Thumbnail gallery)

A generic function graph like this:

plt.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)

And this Scatter diagram (I don’t know how to say it in Chinese…):

plt.scatter(x, y, s=area, alpha=0.5)

Delicate curves, translucent colors. Show your noble and glamorous personality, the most important thing is that you can do it with just one line of code. From then on, I no longer have to endure the painful color matching in Matlab and GNUPlot.

Want to draw 3D data? No problem (mayavi may be more convenient):

ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)

You can have four lines of code (the last three lines are to draw contour lines on the coordinate plane, strictly speaking, it is still one line).

In addition, you are a vector field, and you can handle any weird needs of the network:

plt.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn) plt.colorbar()

plt.triplot(x, y, triangles, 'go-')
plt. title('triplot of user-specified triangulation')
plt. xlabel('Longitude (degrees)')
plt.ylabel('Latitude (degrees)')
  
ax = plt.subplot(111, polar=True)
bars = ax.bar(theta, radii, width=width, bottom=0.0)

This is not over yet, Matplotlib also supports the insertion of Latex formulas, when other people’s drawings are still like this (the following pictures are quoted from Matplotlib Tutorial (translation))

You can turn it into this:

If you use IPython as the running terminal (this picture is drawn by yourself~):

It is simply a divine tool, is there any!

Action is worse than heartbeat, what are you waiting for?

One more thing to add, matplotlib can also use xkcd style graphs~

(The picture is quoted from the Internet)

In addition, for more exciting content combined with IPython Notebook, please see http://nbviewer.ipython.org/

If you find it troublesome to install and you happen to be on a Windows system, you can try a distribution of Python winpython – Portable Scientific Python 2/3 32/64bit Distribution for Windows.

In view of some students questioning whether matplotlib can draw the image shown in the title, I will use matplotlib to draw the image in the title as follows:

Code here: https://gist.github.com/coldfog/c479124328fc6bb8b789

Code here: https://gist.github.com/coldfog/5da63a6958fc0a949b52

I saw someone downstairs saying that the color scheme is good-looking, alas…then I will post a few too…but I didn’t write it because of the space limit.

First of all, python has a special color matching package jiffyclub/brewer2mpl, which provides exquisite color matching from an artistic point of view (click here to experience ColorBrewer: Color Advice for Maps).

In addition, there are some libraries dedicated to beautifying plots, which are very convenient to use, such as olgabot/prettyplotlib.

Not much nonsense, the picture above is king. (The picture below comes from the Internet)

Some people may say that complex settings are required, but it is not necessary. For example, in the picture above, you only need to add one more parameter:

cmap=brewer2mpl.get_map('RdBu', 'diverging', 8, reverse=True).mpl_colormap,

Downstairs is about statistical drawing. Well seaborn is a statistical drawing library that calls matplotlib, above: (https://github.com/mwaskom/seaborn)

The code is one line, and the following is almost all one line. No other settings are made, and the default is like this. I will not post other codes:

g = sns. jointplot(x1, x2, kind="kde", size=7, space=0)

Good article recommendation

Python zero-based tutorial (quick start)

The most powerful strategy for getting started with Python, but you can’t start with zero-based self-study? It’s right to start with crawlers