python画曲线图
科研作图代码记录
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from parameters import *
font_size = 16
bwith = 2 # 边框宽度设置为2
plt.rcParams['xtick.direction'] = 'in' #坐标刻度方向
plt.rcParams['ytick.direction'] = 'in'
plt.rcParams['ytick.labelsize'] = font_size #刻度字体
plt.rcParams['xtick.labelsize'] = font_size
ax = plt.gca() # 获取边框
# ax.spines['top'].set_color('red') # 设置上‘脊梁’为红色
ax.spines['right'].set_color('none') # 设置上‘脊梁’为无色
ax.spines['bottom'].set_linewidth(bwith)
ax.spines['left'].set_linewidth(bwith)
ax.spines['top'].set_linewidth(bwith)
ax.spines['right'].set_linewidth(bwith)
def plot_n_R(R_all, exp_data = False):
labels = [
'Bending radius=2cm',
'Bending radius=3cm',
'Bending radius=5cm',
'Bending radius=10cm']
linestyle_ = ['-', '--', '-.', ':']
color_ = ['b', 'k', 'm', 'r']
fig, ax = plt.subplots()
markers = ['s', 'v', '^', '>', 'p', '<', '*', '.', 'x']
for i, R in enumerate(R_all):
label = labels[i]
x = np.linspace(0, 2*L, 2*L)
ax.plot(np.linspace(1, 2*L, 2*L-1),
(R[1:] / R[1] - 1) * 100,
linewidth=3,
label=label,
linestyle=linestyle_[i],
color=color_[i])
# marker=markers[i],
# markevery=20 + 2 * i,
# ms = 10,
ax.set_xlabel('Number of bending cycles', fontsize=14)
ax.set_ylabel('$ΔR/R_0$(%)', fontsize=14)
#ax.set_ylim(-5, 180)
ax.legend(prop={'size': 14},
frameon=False,
loc='upper left',
bbox_to_anchor=(-0.015, 1)) # 'family' : 'Times New Roman'
#ax.text(0, 1, '$h_2/h_1=2500$', fontdict={'family': 'Times New Roman', 'size': 16})
fig.set_size_inches(8, 6)
plt.savefig('2021-1-23-测试m')
plt.show()
def plot_3d_w(w):
X = np.arange(0, 2*L, 0.01*L)
Y = np.arange(0, b, 0.01*b)
X, Y = np.meshgrid(X, Y)
Z = 5914158.57835006*sin(pi*X/20)*sin(pi*Y/10)
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.viridis)
plt.show()