我有一个相当复杂的绘图程序,我试图尽我所能自动化它,我似乎失去了蒸汽。可以说我有以下列表:
L2_US =[1.550,17.8781291,35.618459,53.191329,70.5660164,87.7105627,104.591588,121.174089,137.421217,153.294033,168.751236,183.748849,198.23988,212.17392,225.496694,238.14954,250.068807,261.185153,271.422729,280.698215,288.919676]
L4_US =[373.62,363.23,353.76,345.12,337.23,330.04,323.48,317.51,312.09,307.16,302.71,298.69,295.08,291.86,289.00,286.47,284.27,282.38,280.77,279.44]
L2_DS =[0,50,100,150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000]
L4_DS =[279.07,276.52,299.70,298.72,297.66,296.52,295.27,293.91,292.41,290.76,288.92,,286.85,284.48,281.71,278.27,424.15,386.02,356.22,332.58,313.69,298.62]
L2_US
和L2_US
是第1行的x和y坐标
L2_DS
和L2_DS
是第2行的x和y坐标
在这个应用程序中,第1行和第2行只有一个交集,我需要:
以下是我目前开发的代码:
import os, csv, sys
import numpy as np
import matplotlib.pyplot as plt
from itertools import product
#Find the closest Momentum values between the two profiles
a,b = sorted(product(L4_DS,L4_US), key=lambda t: abs(t[0]-t[1]))[0]
#Get index of closest momentum values
ds_index = L4_DS.index(a)
us_index = L4_US.index(b)
print 'ds index is '+ str(ds_index)
print 'us indes is ' + str(us_index)
#Ignore the main plot, my question pertains to the second axis plotting
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.set_ylabel('Stage (m)',color='b')
ax1.set_xlabel('Distance (m)')
#Begin of subplot
ax2 = ax1.twinx()
#Upstream Momentum
ax2.plot(L2_US[0:us_index], L4_US[0:us_index], 'r-',label='Momemtum')
#downstream momemtum
ax2.plot(L2_DS[ds_index:], L4_DS[ds_index:], 'r-',label='Momemtum')
ax2.set_ylim([0.8*min(L4_DS),1.2*max(L4_DS)])
ax2.set_ylabel('Momemtum (m$^3$)',color='r')
plt.title('HW_8 Problem 3', fontsize = 14)
plt.show()
此代码查找直到内插值所在的第一行和从最接近的L4_DS
值到所需内插值的第二行的图,但它不是完整的阶梯函数。我不知道对每条线执行插值和插值的最佳方法。