Python Matlab绘制曲线图
hhh江月 人气:0一、简介
我们在这里采用Python中的matplotlib来实现曲线图形的绘制。matplotlib是著名的python绘图库,它提供了一整套绘图API,十分适合交互式绘图。
二、绘制图形
1、第一个曲线图
代码:
具体的绘制的代码如下所示:
import matplotlib.pyplot as plt import numpy as np r = np.array([2072.54, 2076.84, 2085.51, 2103.01, 2129.93, 2162.16, 2200.22, 2242.15, 2285.71, 2328.29, 2350.18, 2364.01, 2364.01, 2343.29, 2300.17, 2252.25, 2208.72, 2166.85, 2132.19, 2103.01, 2085.51, 2075.77, 2072.54]) b_ = np.array([30.159, 27.143, 24.127, 21.111, 18.096, 15.080, 12.064, 9.048, 6.032, 3.016, 1.508, 0, -1.508, -3.016, -6.032, -9.048, -12.064, -15.080, -18.096, -21.111, -24.127, -27.143, -30.159]) b = b_ * pow(10, -4) plt.plot(b, r) plt.xlabel("B/T") plt.ylabel("R/Ω") plt.title("GMB R-B (decreasing B)") plt.show()
效果:
2、第二个图形
代码:
代码与上一个的代码其实是比较相似的:
import matplotlib.pyplot as plt import numpy as np r = np.array([2072.53, 2076.81, 2085.47, 2103.00, 2129.90, 2162.11, 2200.20, 2242.06, 2285.66, 2328.24, 2350.13, 2364.00, 2363.96, 2343.19, 2300.20, 2252.29, 2208.76, 2166.89, 2132.20, 2103.05, 2085.50, 2075.81, 2072.56]) b_ = np.array([30.159, 27.143, 24.127, 21.111, 18.096, 15.080, 12.064, 9.048, 6.032, 3.016, 1.508, 0, -1.508, -3.016, -6.032, -9.048, -12.064, -15.080, -18.096, -21.111, -24.127, -27.143, -30.159]) b = b_ * pow(10, -4) plt.plot(b, r) plt.xlabel("B/T") plt.ylabel("R/Ω") plt.title("GMB R-B (increasing B)") plt.show()
效果:
3、第三个图形
代码:
代码基本是形同的啦:
import matplotlib.pyplot as plt import numpy as np v = np.array([274, 270, 261, 243, 219, 189, 155, 118, 81, 48, 34, 21]) b_ = np.array([30.159, 27.143, 24.127, 21.111, 18.096, 15.080, 12.064, 9.048, 6.032, 3.016, 1.508, 0]) b = b_ * pow(10, -4) plt.plot(b, v) plt.xlabel("B/T") plt.ylabel("V/mV") plt.title("GMB V-B") plt.show()
效果:
4、第四个图形
代码:
代码其实都是基本一样的,只不过主要是更换了数据啦:
import matplotlib.pyplot as plt import numpy as np w = np.array([43.5, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 101, 104]) v = np.array([0, 5.7, 35.0, 53.8, 45.9, 7.7, -45.7, -51.9, -32.6, -1.8, 34.5, 53.1, 39.2, -10.1, -47.9, -51.4, -29.5, 5.6, 34.4, 52.4, 40.9, -5.2]) plt.plot(w, v) plt.xlabel("θ/rad") plt.ylabel("V/mV") plt.title("GMB V-θ") plt.show()
效果:
5.画出指定区间的一个多项式函数:
import numpy as np import matplotlib.pyplot as plt X = np.linspace(-4, 4, 1024) Y = .25 * (X + 4.) * (X + 1.) * (X - 2.) plt.title('$f(x)=\\frac{1}{4}(x+4)(x+1)(x-2)$') plt.plot(X, Y, c = 'g') plt.show()
总结
加载全部内容