我是靠谱客的博主 粗心香水,最近开发中收集的这篇文章主要介绍用Python画大学物理实验曲线,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
def MSE(y1, y2):
return np.sum((y1 - y2) ** 2) / len(y1)
matplotlib.rcParams['font.family'] = 'YouYuan'
# 幼圆字体
plt.figure("Ur与ln(rb/r)关系曲线", dpi=150)
# 命名绘图窗口plt.figure(),调整清晰度
plt.xlabel("Ur")
plt.ylabel("ln(rb/r)")
plt.title('Ur与ln(rb/r)关系曲线')
plt.grid(color='r', linestyle='--', linewidth=0.5)
# 设置网格
x = np.arange(2, 8, 0.01)
y = 0.2708 * x
plt.plot(x, y)
x = np.arange(2, 9, 1)
y = 0.2708 * x
plt.plot(x, y, 'ob')
for xx, yy in zip(x, y):
plt.text(xx + 0.2, yy, "{:.3f}".format(yy))
# 添加注解
plt.axis([2, 9, 0.4, 2.4])
plt.show()
y2 = y[::-1]
x = np.array([1.407, 1.8, 2.129, 2.714, 3.229, 3.971, 4.814])
y = np.log(7.5 / x)
print(MSE(y, y2))
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import interp1d
def MSE(y1, y2):
return np.sum((y1 - y2) ** 2) / len(y1)
matplotlib.rcParams['font.family'] = 'YouYuan'
# 幼圆字体
#
# plt.figure("80cm光伏组件伏安特性曲线", dpi=150)
# 命名绘图窗口
# plt.xlabel("V")
# plt.ylabel("I")
#
# U80 = np.array([0.02, 0.47, 2.05, 3.58, 5.01, 5.69, 6.35, 7.34, 8.36, 8.43, 8.61,
#
8.64, 8.74, 9.21, 9.29, 9.84, 9.93])
#
# I80 = np.array([77.5, 76.5, 76.3, 75.6, 74.4, 73.5, 72.7, 66.3, 60.7, 44.9, 39.4, 35.2,
#
29.2, 24.2, 18.9, 11.3, 6.3])
# P80 = [xx * yy for xx, yy in zip(U80, I80)]
# idx = 0
# Pm80 = 0
# for i, p in enumerate(P80):
#
if p > Pm80:
#
idx = i
#
Pm80 = p
# Im80, Um80, Rm80 = I80[idx], U80[idx], U80[idx] / I80[idx]
# print(Im80, Um80, Rm80, end='n')
# Isc80, Voc80 = 7 / 6 * Im80, 7 / 6 * Um80
# FF80 = Pm80 / Voc80 / Isc80
# print(Isc80, Voc80, FF80, end='n')
# plt.title('80cm光伏组件伏安特性曲线')
# plt.grid(color='r', linestyle='--', linewidth=0.5)
# 设置网格
#
# xnew = np.linspace(U80.min(), U80.max(), 300)
# 300 represents number of points to make between T.min and T.max
# func = interp1d(U80, I80, kind=1)
# ynew = func(xnew)
# plt.plot(xnew, ynew)
# plt.plot(U80, I80, 'ob')
# i = 0
# for xx, yy in zip(U80, I80):
#
i += 1
#
if i % 2 == 0:
#
plt.text(xx + 0.3, yy + 2, "{:.1f}".format(yy))
# 添加注解
#
else:
#
plt.text(xx - 0.9, yy - 2, "{:.1f}".format(yy))
# plt.axis([0, 10, 0, 100])
# plt.xticks(np.arange(0, 11, 1))
# plt.yticks(np.arange(0, 110, 10))
# plt.show()
plt.figure("60cm光伏组件伏安特性曲线", dpi=150)
# 命名绘图窗口
plt.xlabel("V")
plt.ylabel("I")
U60 = np.array([0.01, 0.73, 2.09, 2.21, 3.41, 4.72, 5.9, 7.04, 7.75, 8.59, 8.87, 9.15, 9.21,
9.23, 9.27, 9.38, 9.48, 9.55, 9.61, 9.66, 9.7, 9.71, 9.77])
I60 = np.array([133.2, 132.4, 132.1, 131.7, 131.7, 130.6, 128.7, 126.1, 118.6, 100.3, 84.7,
68.2, 63.9, 60, 56.6, 48.6, 39.2, 32.8, 28.3, 24.7, 21.6, 16.4, 14.1])
P60 = [xx * yy for xx, yy in zip(U60, I60)]
idx = 0
Pm60 = 0
for i, p in enumerate(P60):
if p > Pm60:
idx = i
Pm60 = p
Im60, Um60, Rm60 = I60[idx], U60[idx], U60[idx] / I60[idx]
print(Im60, Um60, Rm60, end='n')
Isc60, Voc60 = 7 / 6 * Im60, 7 / 6 * Um60
FF60 = Pm60 / Voc60 / Isc60
print(Isc60, Voc60, FF60, end='n')
plt.title('60cm光伏组件伏安特性曲线')
plt.grid(color='r', linestyle='--', linewidth=0.5)
# 设置网格
xnew = np.linspace(U60.min(), U60.max(), 300)
# 300 represents number of points to make between T.min and T.max
func = interp1d(U60, I60, kind=1)
ynew = func(xnew)
plt.plot(xnew, ynew)
plt.plot(U60, I60, 'ob')
i = 0
for xx, yy in zip(U60, I60):
i += 1
if i % 2 == 0:
plt.text(xx + 0.3, yy + 2, "{:.1f}".format(yy))
# 添加注解
else:
plt.text(xx - 0.9, yy - 2, "{:.1f}".format(yy))
plt.axis([0, 10, 0, 140])
plt.xticks(np.arange(0, 11, 1))
plt.yticks(np.arange(0, 150, 10))
plt.show()
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
def MSE(y1, y2):
return np.sum((y1 - y2) ** 2) / len(y1)
matplotlib.rcParams['font.family'] = 'YouYuan'
# 幼圆字体
plt.figure("改装电流表的校正曲线2", dpi=150)
# 命名绘图窗口plt.figure(),调整清晰度
plt.xlabel("改装表读数")
plt.ylabel("示值误差△I")
plt.title('改装电流表的校正曲线2')
plt.grid(color='r', linestyle='--', linewidth=0.5)
# 设置网格
x = np.arange(0.2, 1.2, 0.2)
y = [0.008, 0.0055, 0.001, 0.007, 0.006]
plt.plot(x, y)
plt.plot(x, y, 'ob')
for xx, yy in zip(x, y):
plt.text(xx, yy+0.0005, "{:.3f}".format(yy))
# 添加注解
plt.axis([0.2, 1, 0.001, 0.009])
plt.show()
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
def MSE(y1, y2):
return np.sum((y1 - y2) ** 2) / len(y1)
matplotlib.rcParams['font.family'] = 'YouYuan'
# 幼圆字体
# plt.figure("Im和磁感应强度B的关系曲线", dpi=150)
# 命名绘图窗口plt.figure(),调整清晰度
# plt.xlabel("Im")
# plt.ylabel("B")
# plt.title('Im和磁感应强度B的关系曲线')
# plt.grid(color='r', linestyle='--', linewidth=0.5)
# 设置网格
# x = np.arange(50, 550, 50)
# U = [2.526, 2.549, 2.572, 2.595, 2.618, 2.64, 2.663, 2.685, 2.708, 2.731]
# y = [(i - 2.5) / 31.25 *1000 for i in U]
# plt.plot(x, y, 'ob')
# plt.plot(x, y)
# for xx, yy in zip(x, y):
#
plt.text(xx + 15, yy-0.1, "{:.3f}".format(yy))
# 添加注解
# plt.axis([0, 500, 0, 8])
# plt.xticks(np.arange(0, 600, 50))
# plt.yticks(np.arange(0, 8.5, 0.5))
# plt.show()
plt.figure("磁感应强度B(x)随位置x的关系曲线", dpi=150)
# 命名绘图窗口plt.figure(),调整清晰度
plt.xlabel("x")
plt.ylabel("B")
plt.title('磁感应强度B(x)随位置x的关系曲线')
plt.grid(color='r', linestyle='--', linewidth=0.5)
# 设置网格
x = np.arange(-14, 16, 1)
U = [2.525, 2.547, 2.577, 2.599, 2.609, 2.613, 2.615, 2.616, 2.617, 2.618,
2.618, 2.618, 2.618, 2.618, 2.618, 2.618, 2.618, 2.618, 2.618, 2.617,
2.617, 2.616, 2.616, 2.615, 2.613, 2.608, 2.598, 2.574, 2.542, 2.523]
U2 = [1.8083, 2.7158, 3.1713, 3.33695, 3.464, 3.5143,3.5433,
3.5613, 3.573, 3.5808, 3.5858, 3.589, 3.5907, 3.5915]
t = U2[::-1]
U2 += t
y = ["{:.3f}".format(1000 * (i - 2.5) / 31.25) for i in U]
y = [float(i) for i in y]
plt.plot(x, y, 'ob')
plt.plot(x, y)
i = 0
print(y)
for xx, yy in zip(x, y):
i += 1
if i % 2 == 0:
plt.text(xx, yy-0.15, "{:.1f}".format(yy))
# 添加注解
else:
plt.text(xx, yy+0.08, "{:.1f}".format(yy))
x = np.arange(-13, 15, 1)
plt.plot(x, U2, 'or')
plt.plot(x, U2, 'k')
plt.axis([-15, 16, 0, 4])
plt.xticks(np.arange(-15, 16, 1))
plt.yticks(np.arange(0, 4, 0.5))
plt.show()
#
# plt.figure("亥姆霍兹线圈轴线上磁场分布的实验曲线", dpi=150)
# 命名绘图窗口plt.figure(),调整清晰度
# plt.xlabel("x")
# plt.ylabel("B")
# # plt.title('载流圆线圈轴线上磁场分布的实验曲线')
# plt.grid(color='r', linestyle='--', linewidth=0.5)
# 设置网格
# x = np.arange(-10, 11, 1)
# B = [1.345, 1.507, 1.692, 1.862, 2.012, 2.135, 2.217, 2.254, 2.243, 2.191, 2.093,
#
1.963, 1.8, 1.63, 1.446, 1.271, 1.107, 0.982, 0.822, 0.717, 0.617]
# plt.plot(x, B, 'ob')
# plt.plot(x, B)
# i = 0
# print(B)
# for xx, yy in zip(x, B):
#
i += 1
#
if i % 2 == 0:
#
plt.text(xx, yy - 0.01, "{:.3f}".format(yy))
# 添加注解
#
else:
#
plt.text(xx, yy + 0.01, "{:.3f}".format(yy))
# x = np.arange(-13, 15, 1)
# plt.show()

最后

以上就是粗心香水为你收集整理的用Python画大学物理实验曲线的全部内容,希望文章能够帮你解决用Python画大学物理实验曲线所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(35)

评论列表共有 0 条评论

立即
投稿
返回
顶部