def corr_plot(): #What args """ """ #fig, ax #how to handle these in general 2d # Maybe it's helpful to have args for top plots (ie ax1,2,3) ax1 = plt.subplot2grid((5,5), (0,0), colspan=1) # top left ax1.plot([0,-1], color='black') ax1.text(.18, -.78, r'$A(\nu_2)$', size=12) ax1.text(.55, -.35, r'$A(\nu_1)$', size=12) ax2 = plt.subplot2grid((5,5), (0,1), colspan=4) # top ax3 = plt.subplot2grid((5,5), (1,0), colspan=1, rowspan=4) #left ax4 = plt.subplot2grid((5,5), (1, 1), colspan=4, rowspan=4) #main contour ax4.yaxis.tick_right() ax4.xaxis.tick_bottom() #remove top xticks ax4.yaxis.set_label_position('right') ax4.set_xlabel('x label') ax4.set_ylabel('y label') # Replace with real data x = np.linspace(0, 100*np.pi, 200) ax2.plot(np.sin(x), color='black') # Swap x,y to plot correctly on ax3!! y = np.cos(x) ax3.plot(y,x, color='black') # Contour test data X, Y = np.meshgrid(x, y) Z = X * Y ax4.contour(X,Y,Z) fig = plt.gcf() fig.suptitle('Title', fontsize=20) # Hide axis labels for ax in [ax1, ax2, ax3]: pu.hide_axis(ax, axis='both', hide_everything = True) plt.subplots_adjust(hspace = 0, wspace=0) return (ax1, ax2, ax3, ax4)
def quad_plot(ts, *plotargs, **plotkwds): """ Output a matplotlib figure with full spectra, absorbance, area and stripchart. Figure should be plotly convertable through py.iplot_mpl(fig) assuming one is signed in to plotly through py.sign_in(user, apikey). Parameters ----------- title : str Title of the overall figure striplegend : bool (False) Add a legend to the strip chart colormap : string ('jet') Colormap applied to full and absorbance spectra. 'Jet' is applid to strip chart regardless. tight_layout: bool (False) Calls mpl.fig.tight_layout() """ title = plotkwds.pop('title', '') tight_layout = plotkwds.pop('tight_layout', False) f, axes = put.splot(2,2, fig=True, figsize=(8,8)) f.suptitle(title, fontsize=20) if tight_layout: f.tight_layout() cmap = plotkwds.pop('colormap', 'jet') strip_cmap = 'spectral' striplegend = plotkwds.pop('striplegend', False) specplot(ts, *plotargs, ax=axes[0], title='Spectra', colormap = cmap, fig=f, #for colorbar **plotkwds) range_timeplot(ts.wavelength_slices(8), ax=axes[1], legend=False, colormap = strip_cmap, title='Spectral Slices', **plotkwds) normplot(ts, *plotargs, ax=axes[2], colormap=cmap, title='Normalized', **plotkwds) areaplot(ts, *plotargs, ax=axes[3], title='Area', fig=f, **plotkwds) # Custom legend to strip chart (http://matplotlib.org/users/legend_guide.html#multicolumn-legend) if striplegend: axes[1].legend(loc='lower center', ncol=4, fontsize=5, # mode='expand', bbox_to_anchor=(0.5,-0.1)) for a in (axes[1], axes[3]): a.yaxis.tick_right() a.yaxis.set_label_position("right") # Remove y-axis of area/stripchart put.hide_axis(axes[0], axis='x') put.hide_axis(axes[1], axis='x') #axes[1].get_yaxis().set_ticklabels([])#set_visible(False) #axes[3].get_yaxis().set_ticklabels([]) #axes[0].get_xaxis().set_ticklabels([]) #axes[1].get_xaxis().set_ticklabels([]) return f
def _gencorr2d(xx, yy, zz, a1_label=r'$\bar{A}(\nu_1)$', a2_label=r'$\bar{A}(\nu_2)$', **contourkwds): """ Abstract layout for 2d correlation analysis plot. **contourkwds Passed directly to _gen2d; includes keywords like xlabel, ylabel and so forth. """ # Maybe this should take X, Y, Z not ts #fig, ax #how to handle these in general 2d # Maybe it's helpful to have args for top plots (ie ax1,2,3) title = contourkwds.pop('title', '') cbar = contourkwds.pop('cbar', False) grid = contourkwds.pop('grid', True) #Adds grid to plot and side plots cbar_nticks = contourkwds.pop('cbar_nticks', 5) #Number ticks in colorbar contourkwds.setdefault('contours', 20) contourkwds.setdefault('fill', True) ax1 = plt.subplot2grid((5,5), (0,0), colspan=1) # top left plt.subplots_adjust(hspace = 0, wspace=0) # Remove whitespace ax1.plot([0,-1], color='black') ax1.text(.18, -.78, a1_label, size=12) ax1.text(.55, -.35, a2_label, size=12) ax2 = plt.subplot2grid((5,5), (0,1), colspan=4) # top ax3 = plt.subplot2grid((5,5), (1,0), colspan=1, rowspan=4) #left ax4 = plt.subplot2grid((5,5), (1, 1), colspan=4, rowspan=4) #main contour ax3.invert_xaxis() ax4.yaxis.tick_right() ax4.xaxis.tick_bottom() #remove top xticks ax4.yaxis.set_label_position('right') ax4, contours = _gen2d(xx, yy, zz, ax=ax4, **contourkwds) # plt.colorbar(ax4) #oesn't work http://matplotlib.org/examples/pylab_examples/contourf_demo.html # Bisecting line ax4.plot(ax4.get_xlim(), ax4.get_ylim(), ls = '--', color='black', linewidth=1) fig = plt.gcf() if grid: ax2.grid() ax3.grid() ax4.grid() # Hide axis labels for ax in [ax2, ax3]: if grid: pu.hide_axis(ax, axis='both', axislabel=True, ticklabels=True) else: pu.hide_axis(ax, axis='both', hide_everything = True) pu.hide_axis(ax1, axis='both', hide_everything=True) # Handles its own colorbar (See links below; important) # http://stackoverflow.com/questions/13784201/matplotlib-2-subplots-1-colorbar # http://matplotlib.org/api/colorbar_api.html#matplotlib.colorbar.make_axes if cbar: if cbar in ['left', 'right', 'top', 'bottom']: # if bottom or right, should repad this location = cbar else: location = 'top' cax,kw = mplcbar.make_axes([ax1, ax2, ax3, ax4], location=location, pad = 0.05, aspect = 30, #make skinnier shrink=0.75) cb = fig.colorbar(contours, cax=cax,**kw)# ticks=[0,zz.max().max()], **kw) cb.locator = mplticker.MaxNLocator(nbins=cbar_nticks+1) #Cuts off one usually cb.update_ticks() fig.suptitle(title, fontsize='large') # Still overpads return (ax1, ax2, ax3, ax4)
def _gencorr2d(xx, yy, zz, a1_label=r'$\bar{A}(\nu_1)$', a2_label=r'$\bar{A}(\nu_2)$', **contourkwds): """ Abstract layout for 2d correlation analysis plot. **contourkwds Passed directly to _gencontour; includes keywords like xlabel, ylabel and so forth. """ # Maybe this should take X, Y, Z not ts #fig, ax #how to handle these in general 2d # Maybe it's helpful to have args for top plots (ie ax1,2,3) title = contourkwds.pop('title', '') cbar = contourkwds.pop('cbar', False) grid = contourkwds.pop('grid', True) #Adds grid to plot and side plots cbar_nticks = contourkwds.pop('cbar_nticks', 5) #Number ticks in colorbar contourkwds.setdefault('contours', 20) contourkwds.setdefault('fill', True) # This will create a fig ax1 = plt.subplot2grid((5, 5), (0, 0), colspan=1) # top left plt.subplots_adjust(hspace=0, wspace=0) # Remove whitespace ax1.plot([0, -1], color='black') ax1.text(.18, -.78, a1_label, size=12) ax1.text(.55, -.35, a2_label, size=12) ax2 = plt.subplot2grid((5, 5), (0, 1), colspan=4) # top ax3 = plt.subplot2grid((5, 5), (1, 0), colspan=1, rowspan=4) #left ax4 = plt.subplot2grid((5, 5), (1, 1), colspan=4, rowspan=4) #main contour ax3.invert_xaxis() ax4.yaxis.tick_right() ax4.xaxis.tick_bottom() #remove top xticks ax4.yaxis.set_label_position('right') ax4, contours = _gen2d3d(xx, yy, zz, ax=ax4, **contourkwds) # plt.colorbar(ax4) #oesn't work http://matplotlib.org/examples/pylab_examples/contourf_demo.html # Bisecting line ax4.plot(ax4.get_xlim(), ax4.get_ylim(), ls='--', color='black', linewidth=1) # Fig is created by _gen2d in ax4 _gen2d3d fig = plt.gcf() if grid: ax2.grid() ax3.grid() ax4.grid() # Hide axis labels for ax in [ax2, ax3]: if grid: pu.hide_axis(ax, axis='both', axislabel=True, ticklabels=True) else: pu.hide_axis(ax, axis='both', hide_everything=True) pu.hide_axis(ax1, axis='both', hide_everything=True) # Handles its own colorbar (See links below; important) # http://stackoverflow.com/questions/13784201/matplotlib-2-subplots-1-colorbar # http://matplotlib.org/api/colorbar_api.html#matplotlib.colorbar.make_axes if cbar: if cbar in ['left', 'right', 'top', 'bottom']: # if bottom or right, should repad this location = cbar else: location = 'top' cax, kw = mplcbar.make_axes( [ax1, ax2, ax3, ax4], location=location, pad=0.05, aspect=30, #make skinnier shrink=0.75) cb = fig.colorbar(contours, cax=cax, **kw) # ticks=[0,zz.max().max()], **kw) cb.locator = mplticker.MaxNLocator(nbins=cbar_nticks + 1) #Cuts off one usually cb.update_ticks() fig.suptitle(title, fontsize='large') # Still overpads return (ax1, ax2, ax3, ax4)
def quad_plot(ts, *plotargs, **plotkwds): """ Output a matplotlib figure with full spectra, absorbance, area and stripchart. Figure should be plotly convertable through py.iplot_mpl(fig) assuming one is signed in to plotly through py.sign_in(user, apikey). Parameters ----------- title : str Title of the overall figure striplegend : bool (False) Add a legend to the strip chart colormap : string ('jet') Colormap applied to full and absorbance spectra. 'Jet' is applid to strip chart regardless. tight_layout: bool (False) Calls mpl.fig.tight_layout() """ title = plotkwds.pop('title', '') tight_layout = plotkwds.pop('tight_layout', False) f, axes = put.splot(2, 2, fig=True, figsize=(8, 8)) f.suptitle(title, fontsize=20) if tight_layout: f.tight_layout() cmap = plotkwds.pop('colormap', 'jet') strip_cmap = 'spectral' striplegend = plotkwds.pop('striplegend', False) ts.plot( *plotargs, ax=axes[0], title='Spectra', colormap=cmap, fig=f, #for colorbar **plotkwds) range_timeplot(ts.wavelength_slices(8), ax=axes[1], legend=False, colormap=strip_cmap, title='Spectral Slices', **plotkwds) ts.plot(*plotargs, iunit='r', ax=axes[2], colormap=cmap, title='Normalized', **plotkwds) areaplot(ts, *plotargs, ax=axes[3], title='Area', fig=f, **plotkwds) # Custom legend to strip chart (http://matplotlib.org/users/legend_guide.html#multicolumn-legend) if striplegend: axes[1].legend( loc='lower center', ncol=4, fontsize=5, # mode='expand', bbox_to_anchor=(0.5, -0.1)) for a in (axes[1], axes[3]): a.yaxis.tick_right() a.yaxis.set_label_position("right") # Remove y-axis of area/stripchart put.hide_axis(axes[0], axis='x') put.hide_axis(axes[1], axis='x') #axes[1].get_yaxis().set_ticklabels([])#set_visible(False) #axes[3].get_yaxis().set_ticklabels([]) #axes[0].get_xaxis().set_ticklabels([]) #axes[1].get_xaxis().set_ticklabels([]) return f