ADD file via upload

matlib
p7m86wfya 6 months ago
parent 81af904bda
commit bc4efeeb15

@ -0,0 +1,105 @@
import matplotlib
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def PolylineG1(left,rigt,density,A,displacement):
x=np.linspace(left,rigt,density)
y=A*x + displacement
yLeft=A*left + displacement
yRigt=A*rigt + displacement
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set(xlim=[left, rigt], ylim=[yLeft, yRigt], title='一次函数',
ylabel='Y-Axis', xlabel='X-Axis')
plt.plot(x,y)
plt.show()
def PolylineG2(left,rigt,density,A,B,displacement):
x = np.linspace(left, rigt, density)
y = A * (x**2) + B*x + displacement
yLeft = A * (left ** 2) + B * left + displacement
yRigt = A * (rigt ** 2) + B * rigt + displacement
ymind = A * ((-A/2*B) ** 2) + B * (-A/2*B) + displacement
if(left<(-A/2*B)<rigt):
yMax=max(yLeft,yRigt)
Max=max(ymind,yMax)
Min=min(ymind,yMax)
else:
Max=max(yLeft,yRigt)
Min=min(yLeft,yRigt)
fig = plt.figure()
ax = fig.add_subplot(111)
#ax.set(xlim=[left, rigt], ylim=[Min, Max], title='二次函数',
# ylabel='Y-Axis', xlabel='X-Axis')
plt.plot(x, y)
plt.show()
def PolylineG3(left,rigt,density,A,B,D,displacement):
x = np.linspace(left, rigt, density)
y = A * (x**3) + B*(x**2)+ D*x + displacement
yLeft = A * (left**3) + B*(left**2)+ D*left + displacement
yRigt = A * (rigt**3) + B*(rigt**2)+ D*rigt + displacement
Max = max(yLeft, yRigt)
Min = min(yLeft, yRigt)
fig = plt.figure()
ax = fig.add_subplot(111)
#ax.set(xlim=[left, rigt], ylim=[Min, Max], title='三次函数',
# ylabel='Y-Axis', xlabel='X-Axis')
plt.plot(x, y)
plt.show()
def Sine(left,rigt,density,displacement):
x=np.linspace(left,rigt,density)*np.pi/180
d=displacement*np.pi/180
y=np.sin(d+x)
yLeft = -1
yRigt = 1
fig = plt.figure()
ax = fig.add_subplot(111)
# ax.set(xlim=[left, rigt], ylim=[yLeft, yRigt], title='正弦函数',
# ylabel='Y-Axis', xlabel='X-Axis')
plt.plot(x,y)
plt.show()
def Cosine(left,rigt,density,displacement):
x = np.linspace(left, rigt, density) * np.pi / 180
d = displacement * np.pi / 180
y = np.cos(d + x)
yLeft = -1
yRigt = 1
fig = plt.figure()
ax = fig.add_subplot(111)
#ax.set(xlim=[left, rigt], ylim=[yLeft, yRigt], title='余弦函数',
# ylabel='Y-Axis', xlabel='X-Axis')
plt.plot(x, y)
plt.show()
#def ScatterG():
def BarG(x,y):
fig, axes = plt.subplots()
vert_bars = axes.bar(x, y, color='lightblue', align='center')
#horiz_bars = axes[1].barh(x, y, color='lightblue', align='center')
# 在水平或者垂直方向上画线
axes.axhline(0, color='gray', linewidth=2)
#axes[1].axvline(0, color='gray', linewidth=2)
axes.set(title='abs')
plt.show()
def Histogram(x,n_bins):
fig, axes = plt.subplots(nrows=2, ncols=2)
ax0= axes.flatten()
colors = ['red', 'tan', 'lime']
ax0.hist(x, n_bins, density=True, histtype='bar', color=colors, label=colors)
ax0.legend(prop={'size': 10})
ax0.set_title('bars with legend')
fig.tight_layout()
plt.show()
Loading…
Cancel
Save