-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot-examples-root.py
153 lines (112 loc) · 5.48 KB
/
plot-examples-root.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import matplotlib.gridspec as gridspec
from matplotlib.ticker import MultipleLocator
from examples.aero_data.aero_data_loader import AeroDataLoaderInstance
import sciplots
import os
print(plt.style.available)
# exit()
# based on this file dir
current_dir = os.path.dirname(os.path.abspath(__file__))
figures_dir = os.path.join(current_dir, "figures")
if not os.path.exists(figures_dir):
os.makedirs(figures_dir)
# chinese characters directly plotting with roman English
with plt.style.context(["ieee", "latex-sc"]):
fig, ax = plt.subplots(figsize=(3.5, 2.5))
ax.plot(range(5))
ax.text(0.5, 3.,r"$\prescript{\mathcal{B}}{}{\boldsymbol{c}_z}$")
# mathbf的字体会随着 text字体而改变
ax.text(1.5, 3.,r"$\prescript{\mathcal{B}}{}{\mathbf{c}_z}$")
ax.text(1.5, 2.,r"$\prescript{\mathcal{B}}{}{\boldsymbol{c}_z}$")
ax.text(2.5, 3.,r"中国人不骗中国人")
ax.text(2.5, 1.5,r"一眼顶真")
ax.set_xlabel(r"中国人", loc="left")
# set bottom large margin
plt.subplots_adjust(bottom=0.15)
plt.subplots_adjust(left=0.25)
ax.set_ylabel(r"$\prescript{a}{b}{\sum_{i=1}^{n}} = \sum_{i=1}^{n} a_i b_i$")
ax.set_title(r"$\boldsymbol{E} = \boldsymbol{mc}^2$")
fig.savefig(os.path.join(figures_dir, "figure-chinese.pdf"), backend="pgf")
# chinese characters directly plotting with roman English
with plt.style.context(["ieee", "latex"]):
fig, ax = plt.subplots(figsize=(3.5, 2.5))
ax.plot(range(5))
ax.text(0.5, 3.,r"$\prescript{\mathcal{B}}{}{\boldsymbol{c}_z}$")
# mathbf的字体会随着 text字体而改变
ax.text(1.5, 3.,r"$\prescript{\mathcal{B}}{}{\mathbf{c}_z}$")
ax.text(1.5, 2.,r"$\prescript{\mathcal{B}}{}{\boldsymbol{c}_z}$")
# set bottom large margin
plt.subplots_adjust(bottom=0.15)
plt.subplots_adjust(left=0.25)
ax.set_ylabel(r"$\prescript{a}{b}{\sum_{i=1}^{n}} = \sum_{i=1}^{n} a_i b_i$")
ax.set_title(r"$\boldsymbol{E} = \boldsymbol{mc}^2$")
fig.savefig(os.path.join(figures_dir, "figure-english.pdf"), backend="pgf")
def initialize_figure():
"""Initialize a multi-panel figure with a grid layout."""
fig_height = 3
letter_column_width = 3.25
fig = plt.figure(figsize=(letter_column_width, fig_height), constrained_layout=False)
gs = gridspec.GridSpec(2, 1, figure=fig)
gs.update(wspace=0.3, hspace=0.25)
ax1 = fig.add_subplot(gs[0, 0]) # Cx plot
ax2 = fig.add_subplot(gs[1, 0]) # Cz plot
# Add more padding at the bottom for x-axis labels
plt.subplots_adjust(bottom=0.15)
plt.subplots_adjust(left=0.2)
return fig, [ax1, ax2]
with plt.style.context(["ieee", "latex", "ticks-inward"]):
fig, axs = initialize_figure()
alpha_deg, cx, cz = AeroDataLoaderInstance.get_data()
axs[0].plot(alpha_deg, cx)
axs[1].plot(alpha_deg, cz)
axs[1].set_xlabel(r"$\alpha~[\mathrm{deg}]$")
axs[0].set_ylabel(r"$\prescript{\mathcal{B}}{}{\boldsymbol{c}_x}~[\mathrm{kg/m}]$")
axs[1].set_ylabel(r"$\prescript{\mathcal{B}}{}{\boldsymbol{c}_z}~[\mathrm{kg/m}]$")
# finetuning
for ax in axs:
sciplots.set_minor_ticks_style(ax)
# set ticks points for first plot (cx)
axs[0].set_yticks([-0.04, -0.02, 0, 0.02, 0.04])
# Set minor ticks for y-axis (4 between each major tick)
major_spacing = 0.02 # Distance between major ticks
minor_spacing = major_spacing/5 # 4 minor ticks between majors
axs[0].yaxis.set_minor_locator(MultipleLocator(minor_spacing))
# seting x ticks lable false
axs[0].set_xticklabels([])
# set ticks points for second plot (cz)
axs[1].set_yticks([-0.3, -0.15, 0, 0.15, 0.3])
# Set minor ticks for y-axis (4 between each major tick)
major_spacing = 0.15 # Distance between major ticks
minor_spacing = major_spacing/5 # 4 minor ticks between majors
axs[1].yaxis.set_minor_locator(MultipleLocator(minor_spacing))
fig.savefig(os.path.join(figures_dir, "figure-aero-lyu.pdf"), backend="pgf")
with plt.style.context(["ieee", "latex-sc", "ticks-inward"]):
fig, axs = initialize_figure()
alpha_deg, cx, cz = AeroDataLoaderInstance.get_data()
axs[0].plot(alpha_deg, cx)
axs[1].plot(alpha_deg, cz)
axs[1].set_xlabel(r"攻角~[deg]")
axs[0].set_ylabel(r"$\prescript{\mathcal{B}}{}{\boldsymbol{c}_x}~[\mathrm{kg/m}]$")
axs[1].set_ylabel(r"$\prescript{\mathcal{B}}{}{\boldsymbol{c}_z}~[\mathrm{kg/m}]$")
# finetuning
for ax in axs:
sciplots.set_minor_ticks_style(ax)
# set ticks points for first plot (cx)
axs[0].set_yticks([-0.04, -0.02, 0, 0.02, 0.04])
# Set minor ticks for y-axis (4 between each major tick)
major_spacing = 0.02 # Distance between major ticks
minor_spacing = major_spacing/5 # 4 minor ticks between majors
axs[0].yaxis.set_minor_locator(MultipleLocator(minor_spacing))
# seting x ticks lable false
axs[0].set_xticklabels([])
# set ticks points for second plot (cz)
axs[1].set_yticks([-0.3, -0.15, 0, 0.15, 0.3])
# Set minor ticks for y-axis (4 between each major tick)
major_spacing = 0.15 # Distance between major ticks
minor_spacing = major_spacing/5 # 4 minor ticks between majors
axs[1].yaxis.set_minor_locator(MultipleLocator(minor_spacing))
fig.savefig(os.path.join(figures_dir, "figure-aero-lyu-sc.pdf"), backend="pgf")
# 可以发现加入中文英文字体会稍微有一点不一样,但是mathfont还是基本一致