目前,我的表单包含三个变量:
第0步的表格:
XVal = np.array(XVal); YVal = np.array(YVal); ZVal = np.array(ZVal)
Tally = np.array(Tally); Error = np.array(Error)
import pylab as plt
from matplotlib.colors import LogNorm
import matplotlib.cm as cm
import scipy.interpolate
# Sets up a mesh grid over which data points will be plotted
xi, yi = np.linspace(XVal.min(),XVal.max(),100), np.linspace(YVal.min(),YVal.max(),100)
xi, yi = np.meshgrid(xi,yi)
# Function to interpolate data points on mesh grid
doseinterp = scipy.interpolate.Rbf(XVal, YVal, Tally, function='linear')
# - Uses the above function to interpolate data points at mesh grid locations
# from MCNP Mesh Tally data
zi = doseinterp(xi,yi)
# Plots a heat map of Dose Rate over the mesh grid
fig,plt = plt.subplots()
plt.set_title('Z = 0 cm',fontsize=20)
plt.set_xlabel('X (cm)',fontsize=18)
plt.set_ylabel('Y (cm)',fontsize=18)
img1 = plt.imshow(zi,norm=LogNorm(vmin=Tally.min(),vmax=Tally.max()),extent=[XVal.min(),XVal.max(), \
YVal.min(),YVal.max()])
cb = fig.colorbar(img1)
cb.set_label('Magnitude')
fig.savefig('C:\Users\jawebb\Desktop\Dose.png')
plt.clear()
根据问题1和2的答案:我将在get_form()中生成一个变量'data',将在步骤1中使用。
我不确定如何将'数据'传递给第1步。当你使用get_context_data()移动到第1步时,数据似乎被删除。因为数据不是表单中的字段,我不认为get_cleanted_data_for步()有效。有什么建议吗?
答案 0 :(得分:0)
您可以使用get_form_kwargs
方法将变量传递到表单的init:
def get_form_kwargs(self, step):
if step == 'name-of-the-step-you-want-to-pass-data-to':
prev_data = self.storage.get_step_data('name-of-previous-step')
return {
'something': prev_data.get('something'),
}