Here is a summary of the commands used when creating diagrams for science papers with matplotlib's pyplot. I used it mainly as a diagram for physical papers such as Physical review, but it can probably be used in other fields as well. Assuming a two-column paper, The width of the figure is 8 cm for one column and 16 cm for two columns.
import matplotlib.pyplot as plt
I used to import pylab, but pylab seems to be taking some of the numpy and matplotlib functions. The above is used because numpy is imported separately.
You can use rcParams in your code to change diagram parameters in bulk without having to modify each diagram.
plt.rcParams['font.family'] ='sans-serif'#Font to use
plt.rcParams['xtick.direction'] = 'in'#x-axis scale line pointing inward('in')Or outward('out')Or bidirectional('inout')
plt.rcParams['ytick.direction'] = 'in'#y-axis scale line pointing inward('in')Or outward('out')Or bidirectional('inout')
plt.rcParams['xtick.major.width'] = 1.0#Line width of x-axis main scale line
plt.rcParams['ytick.major.width'] = 1.0#Line width of y-axis main scale line
plt.rcParams['font.size'] = 8 #Font size
plt.rcParams['axes.linewidth'] = 1.0#Axis line width edge linewidth. Enclosure thickness
The font'sans-serif'is a character without a "whisker", and the characters usually used in the figures of papers are often without a beard. The font size is 8 because it is about the same size as the caption description.
--Figure size setting
plt.figure(figsize=(3.14,3.14))
The size of the figure is specified in inches and the variables are (width, height). 3.14 inches is about 8 cm. It is good to adjust the height without changing the width.
--Specify the number of digits of the numerical value of the axis:
plt.gca().yaxis.set_major_formatter(plt.FormatStrFormatter('%.3f'))#Display of 3 digits after the y-axis decimal point
--Express the numbers on the axis without using offsets (such as + 1.05e9)
plt.gca().xaxis.get_major_formatter().set_useOffset(False)
--Make the numbers on the axis an integer
plt.gca().yaxis.set_major_locator(ticker.MaxNLocator(integer=True))
--Specify the number of axis scales:
plt.locator_params(axis='y',nbins=6)#y-axis, within 6 pieces.
--Specify the orientation of the axis scale and the position of the frame:
plt.gca().yaxis.set_tick_params(which='both', direction='in',bottom=True, top=True, left=True, right=True)
--Use the following at the end of the command in the figure:
plt.tight_layout()#The graphs do not overlap and fit within the set size of the figure.
plt.savefig('figname.pdf', transparent=True)
plt.savefig('figname.png', transparent=True, dpi=300)
The format of the figure changes by changing the extension. By specifying transparent, the background becomes transparent. dpi is the dot density of the bitmap image. After saving the figure, specify it to the output size such as width 8 cm with TeX or word and use it.
--Color map
plt.contour(X, Y, Z, cmap='viridis') #Draw contour lines with viridis color scheme
For the color scheme, we recommend viridis, which is easy to distinguish even for people with color vision deficiency.
[Memo] We will update it from time to time.
Recommended Posts