Links to help you customize Matplotlib

When drawing a 3dplot graph with Matplotlib, I couldn't write it neatly with the Default settings, so I investigated some customization methods. Here are some links that were useful in that process.

3dplot (surface) color customization

Let's try 3d plot the relationship between ideal gases. Draw P as the Z axis with PV = RT. ・ When no color is specified

PVT.py


ax.plot_surface(v, T, P, rstride=2, cstride=2)
MatplotlibNoColor.PNG

About customizing the color of the surface

Refer to Color Map I changed the color referring to the above link. It's good to be able to actually see the colors and codes visually as shown below. ColorEX.PNG

Apparently, the color changes continuously from the left edge to the right edge depending on the size of the value. I don't like dark colors as a personal preference, so I set GnBu to change from green to blue. It's easy to set up, just add cmap = cm.GnBu to the code above. Change the GnBu part to your liking.

PVT.py


ax.plot_surface(v, T, P, rstride=2, cstride=2, cmap=cm.GnBu)
ColorChange.PNG

The color is getting closer to my taste, but it's still hard to see, probably because the mesh is black and thick.

Resize mesh line

After checking, the following link showed how to change the line size. Resize Line (https://www.getdatajoy.com/examples/python-plots/surface-plot-and-wireframe "Resize Line") It seems that all you have to do is add linewidth = xx (xx is the line size). If the line size is set to a small value such as 0.1, the shape will be as follows.

PVT.py


ax.plot_surface(v, T, P, rstride=2, cstride=2, cmap=cm.GnBu,linewidth=0.1)
LineChange.PNG

It's my personal preference, but it's much closer to my favorite graph.

Bonus (graph title, legend)

By the way, for inputting the legend and title of the X, Y, Z axes of the graph, refer to the link below. Title, Legend In the above example, it is described as follows.

PVT.py


ax.set_title('PVT') 
ax.set_xlabel('v[l/mol]')
ax.set_ylabel('T[K]')
ax.set_zlabel('P[atm]')

Bonus 2 (About overwriting graphs)

Also, it seems that the graph can be overwritten. In the example below, the PVT of the real gas (when propane is calculated by the Soave Redelich Kwong equation) is overwritten when it is treated as an ideal gas as described above. (Ideal gas is written in GnBu and real gas is written in YlOrRd) IdealActual.PNG

Recommended Posts

Links to help you customize Matplotlib
Links to do what you want with Sublime Text
How to use Matplotlib
Site notes to help you use NetworkX with Python
The road to download Matplotlib