def carpet_plot(results, title, xaxis, yaxis, indexing='xy', **kwargs): '''Assumes ordered dict where values have the same shape''' # print title, xaxis, yaxis arg0, val0 = list(results.items())[0] arg1, val1 = list(results.items())[1] arg2, val2 = list(results.items())[2] a = list(range(val0.shape[0])) b = list(range(val0.shape[1])) aa, bb = np.meshgrid(b, a, indexing=indexing) trace1 = go.Contourcarpet( a=aa.ravel(), b=bb.ravel(), z=val2.ravel(), ) trace2 = go.Carpet( a=aa.ravel(), b=bb.ravel(), x=val0.ravel(), y=val1.ravel(), ) traces = [trace1, trace2] layout = go.Layout(title=title, xaxis=xaxis, yaxis=yaxis) return traces, layout
def carpet_plot(results, title, xaxis, yaxis, indexing = 'xy', **kwargs): '''Assumes ordered dict where values have the same shape''' # print title, xaxis, yaxis arg0, val0 = list(results.items())[0] arg1, val1 = list(results.items())[1] arg2, val2 = list(results.items())[2] a = list(range(val0.shape[0])) b = list(range(val0.shape[1])) aa, bb = np.meshgrid(b,a, indexing = indexing) trace1 = go.Contourcarpet( a = aa.ravel(), b = bb.ravel(), z = val2.ravel(), ) trace2 = go.Carpet( a = aa.ravel(), b = bb.ravel(), x = val0.ravel(), y = val1.ravel(), aaxis = dict( tickprefix = ''.format(arg0), smoothing = 0, minorgridcount = 0, type = 'linear', showgrid = False, nticks = 5, dtick=0, tickmode='linear', showticklabels='none', ), baxis = dict( tickprefix = ''.format(arg1), smoothing = 0, minorgridcount = 0, type = 'linear', showgrid = False, nticks = 5, dtick=0, tickmode='linear', showticklabels='none', ) ) traces = [trace1, trace2] layout = go.Layout( title = title, xaxis = xaxis, yaxis = yaxis) return traces, layout
def draw_a_carpet(A,B,Z,X,Y,save_file,valid,cstr,xstr,ystr): minval = round(min(Z),-1) maxval = round(max(Z),-1) wtstep = (maxval-minval)/10 print('range to plot is ',minval,maxval) #define the font font1 =dict( family='Helvetica', size=18 ) #draw color contour trace1 = go.Contourcarpet( a = A, b = B, z = Z, autocontour = False, contours = dict( start = minval, end = maxval, size = wtstep ), line = dict( width = 0.5, smoothing = 0 ) , colorbar = dict( # len = 0.4, x = 0.9, title=cstr, tickfont=font1, titlefont=dict(size=16) ) ) #define carpet location trace2 = go.Carpet( a = A, b = B, x = X, y = Y, aaxis = dict( # tickprefix = 'DL = ', smoothing = 0, nticks = 4, type = 'linear', showticklabels='none', # categoryorder='category ' ), baxis = dict( # tickprefix = 'sigma=', # smoothing = 0, # tickmode = 'array', # tickvals = [min(B),max(B)], # tickfont = font1, showticklabels='none', # nticks = 3, ) ) #========================================================= # highlight valid designs #========================================================= v = [i for i, x in enumerate(valid) if x == 1] x = X[v] y = Y[v] trace3 = go.Scatter( mode = 'markers', x = x, y = y, opacity = 0.2, marker = dict(symbol='circle-dot',size = 10,line = dict(color = 'black', width = 2),color='white'), showlegend = False ) #========================================================= # highlight min and max #========================================================= Zlist = list(Z[v]) highest = max(Zlist) lowest = min(Zlist) ihigh = [ list(Z).index(highest) ] ilow = [ list(Z).index(lowest) ] print(ihigh,ilow,highest,lowest) trace4 = go.Scatter( mode = 'markers', x = X[ilow], y = Y[ilow], marker = dict(symbol='circle-dot',size = 12,line = dict(color = 'green', width = 4),color='white'), showlegend = False ) trace5 = go.Scatter( mode = 'markers', x = X[ihigh], y = Y[ihigh], marker = dict(symbol='circle-dot',size = 12,line = dict(color = 'red', width = 4),color='white'), showlegend = False ) #========================================================= # call plotly interface #========================================================= data = [trace1, trace2,trace3,trace4,trace5] #data = [trace1]#, trace2] layout = go.Layout( margin = dict( t = 30, r = 60, b = 60, l = 70 ), yaxis = dict( # range = [0.0,0.18], title = ystr, titlefont = font1, tickfont = font1 ), xaxis = dict( # range = [min(trace2.x)-2,max(trace2.x)+2], title = xstr, titlefont = font1, tickfont = font1 ) ) # try: # fig = go.Figure(data = data, layout = layout) # py.image.save_as(fig, filename=save_file+'.png') offline.plot({'data':data,'layout':layout},image='svg', auto_open=False, image_width=1000, image_height=500,show_link=False) try: driver = webdriver.PhantomJS(executable_path="/usr/local/bin/phantomjs") except: driver = webdriver.PhantomJS(executable_path="/usr/bin/phantomjs") driver.set_window_size(1000, 500) driver.get('temp-plot.html') driver.save_screenshot(save_file + '.png') print('saving file',save_file+'.png') # except: # py.sign_in('nenanth', 'eLGDoeHWkICx2mqrdpUu') # Replace the username, and API key with your credentials. # fig = go.Figure(data = data, layout = layout) # py.image.save_as(fig, filename=save_file+'.png') return None
for iD in dia_range: for t in t_range: rp1 = pTank('fuel', volF, ullage, 825, iD) lox = pTank('ox', volO, ullage, 825, iD) idVect = np.append(idVect, iD) tVect = np.append(tVect, t) result = np.append(result, rp1.hoopTee() / t) trace1 = go.Carpet(a=idVect, b=tVect, y=result, aaxis=dict( tickprefix='a = ', ticksuffix='diameter, inch', smoothing=1, minorgridcount=9, ), baxis=dict( tickprefix='b = ', ticksuffix='thickness, inch', smoothing=1, minorgridcount=9, )) layout = go.Layout(yaxis=dict( type='log', autorange=True, title='Required material strength, psi', titlefont=dict(family='Courier New, monospace', size=18, color='#7f7f7f'))) data = [trace1]
def carpet_plot(plotdata, y_axis_index, main_contour_indices, constraint_indices, variables_names_with_units): z_contour = np.array(plotdata[constraint_indices[0]:constraint_indices[0] + 1])[0] aa = 0 t1_arrays_a = plotdata[main_contour_indices[1]:main_contour_indices[1] + 1][:, 0, :][0] t1_arrays_b = plotdata[main_contour_indices[0]:main_contour_indices[0] + 1][:, :, 0][0] t1_arrays_z = np.array( plotdata[constraint_indices[0]:constraint_indices[0] + 1])[0] if len(t1_arrays_a) != len(t1_arrays_z[0]): print( 'length of a should match the inner dimension of the data arrays') return if len(t1_arrays_b) != len(t1_arrays_z): print( 'length of b should match the the outer dimension of the data arrays' ) return #starting contour level value t1_start = int(np.amin(z_contour)) # the end contour level value. Must be more than contours.start t1_end = int(np.amax(z_contour)) #step between each contour level t1_size = (np.amax(z_contour) - np.amin(z_contour)) / 6 t1_size = int(round(t1_size)) trace1 = go.Contourcarpet( b=t1_arrays_b, a=t1_arrays_a, z=t1_arrays_z, autocontour= False, #whether or not the contour level attributes are picked contours=dict( start=t1_start, end=t1_end, size=t1_size, coloring="lines", # dash options include "lines" | "none" showlabels=True, labelfont=dict( family='Arial, sans-serif', size=10, color='blue', )), line=dict( width=1, color="red", smoothing=1, dash='dash' # dash options include 'dash', 'dot', and 'dashdot' ), colorbar=dict( len=0.4, y=0.25 #Sets the y position of the color bar (in plot fraction). )) t2_arrays_a = plotdata[main_contour_indices[1]:main_contour_indices[1] + 1][:, 0, :][0] t2_arrays_b = plotdata[main_contour_indices[0]:main_contour_indices[0] + 1][:, :, 0][0] trace2 = go.Carpet( b=t2_arrays_b, a=t2_arrays_a, x=[[1, 2, 3, 4, 5], [1, 1.9, 2.8, 3.9, 4.9], [1, 1.8, 2.7, 3.8, 4.8], [1, 1.7, 2.6, 3.7, 4.7], [1, 1.6, 2.5, 3.6, 4.6]], y=plotdata[y_axis_index:y_axis_index + 1][0], # Range aaxis=dict( tickprefix='T/W = ', type='linear', smoothing=0, minorgridcount=9, # minorgridwidth = 0.6, # minorgridcolor = 'pink', gridcolor= 'magenta', # This changes the color of the grid but not the edges color='magenta', gridwidth=2, title="<b>W/S<br>(psf)</b>", titlefont=dict(family='Arial, sans-serif', size=15, color='black'), tickfont=dict(family='Arial, sans-serif', size=17, color='black'), ), baxis=dict( tickprefix='W/S = ', ticksuffix='psf', type='linear', smoothing=0, minorgridcount=9, # minorgridwidth = 0.6, # minorgridcolor = 'pink', gridcolor='orange', #changes the color of the grid but not the edges color='orange', #changes the color of the edges of the grid. gridwidth=2, tickfont=dict(family='Old Standard TT, serif', size=17, color='black'), title="T/W", titlefont=dict(family='Arial, sans-serif', size=15, color='black'), )) data = [trace1, trace2] layout = go.Layout( plot_bgcolor='white', paper_bgcolor='white', # Plot is a subset of paper! title="Carpet Plot for sensitivity parameters", margin=dict( # This is to dictate the extent of margins around the plot t=60, r=50, b=50, l=70), yaxis=dict( tickprefix='Range = ', ticksuffix='nmi', ticks='outside', showgrid=True, showticklabels=True, # minorgridcount = 1, # minorgridwidth = 0.6, # minorgridcolor = 'pink', gridwidth=2, gridcolor='#bdbdbd', autorange=True, title="<b>Range <br>(nmi)</b>", tickangle=0, tickwidth=2, tickcolor='#000', tickfont=dict(family='Old Standard TT, serif', size=17, color='black'), # range = [4000,5000] # for our own range ), xaxis=dict( ticks='outside', tick0=0, showgrid=True, showticklabels=True, autorange=True # rangemode='nonnegative' # range = [-5,6] # for our own range )) fig = go.Figure(data=data, layout=layout) plotly.offline.plot(fig, filename='carpet_input_format.html') return