def generateChart(obj): r = [] g = [] b = [] for i in range(obj.num_featureX): tempr = [] tempb = [] tempg = [] for j in range(obj.num_featureY): tempr.append(obj.wts_input_map[(i,j)][0]) tempg.append(obj.wts_input_map[(i,j)][1]) tempb.append(obj.wts_input_map[(i,j)][2]) r.append(tempr) g.append(tempg) b.append(tempb) r = np.asarray(r) g = np.asarray(g) b = np.asarray(b) print("Generating the chart...") fig = plt.figure(1) ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8]) kwargs = dict(origin="lower", interpolation="nearest") ax.imshow_rgb(r, g, b, **kwargs) ax.RGB.set_xlim(0., obj.num_featureX) ax.RGB.set_ylim(0.9, obj.num_featureY) plt.draw() plt.show()
def AxesGrid(): import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes def get_demo_image(): # prepare image delta = 0.5 extent = (-3, 4, -4, 3) x = np.arange(-3.0, 4.001, delta) y = np.arange(-4.0, 3.001, delta) X, Y = np.meshgrid(x, y) Z1 = np.exp(-X ** 2 - Y ** 2) Z2 = np.exp(-(X - 1) ** 2 - (Y - 1) ** 2) Z = (Z1 - Z2) * 2 return Z, extent def get_rgb(): Z, extent = get_demo_image() Z[Z < 0] = 0. Z = Z / Z.max() R = Z[:13, :13] G = Z[2:, 2:] B = Z[:13, 2:] return R, G, B fig = plt.figure(1) ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8]) r, g, b = get_rgb() kwargs = dict(origin="lower", interpolation="nearest") ax.imshow_rgb(r, g, b, **kwargs) ax.RGB.set_xlim(0., 9.5) ax.RGB.set_ylim(0.9, 10.6) plt.draw() return plt.gcf()
def demo_rgb2(): fig = plt.figure(2) ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0) r, g, b = get_rgb() kwargs = dict(origin="lower", interpolation="nearest") ax.imshow_rgb(r, g, b, **kwargs) ax.RGB.set_xlim(0., 9.5) ax.RGB.set_ylim(0.9, 10.6) for ax1 in [ax.RGB, ax.R, ax.G, ax.B]: for sp1 in ax1.spines.values(): sp1.set_color("w") for tick in ax1.xaxis.get_major_ticks() + ax1.yaxis.get_major_ticks(): tick.tick1line.set_mec("w") tick.tick2line.set_mec("w") return ax
def demo_rgb2(): fig = plt.figure() ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0) r, g, b = get_rgb() ax.imshow_rgb(r, g, b) for ax1 in [ax.RGB, ax.R, ax.G, ax.B]: ax1.tick_params(axis='both', direction='in') for sp1 in ax1.spines.values(): sp1.set_color("w") for tick in ax1.xaxis.get_major_ticks() + ax1.yaxis.get_major_ticks(): tick.tick1line.set_markeredgecolor("w") tick.tick2line.set_markeredgecolor("w") return ax
def plot2D(low=-1,high=1,res=250,called=False): ##set up both log and linear scale grid of values xx,yy=np.meshgrid(np.logspace(low,high,res),np.logspace(low,high,res)) xxL,yyL=np.meshgrid(np.linspace(low,high,res),np.linspace(low,high,res)) ##calculate all 3 polyomino abundances for the grid rgb=np.array(Twelve(xx,yy)) ##set up special RGB axis fig = plt.figure() ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8]) ##plot the RGB values based on the polyomino abundance ax.imshow_rgb(*rgb[:,:],interpolation='none',origin='lower',extent=[low,high]*2) ##helper method to locate boundary between phenotypes in phase space def getBoundaries(maxes): change_points=defaultdict(list) for r_idx,row in enumerate(maxes): for change in [i for i in range(1,len(row)) if row[i]!=row[i-1]]: change_points[(min(row[change-1],row[change]),max(row[change-1],row[change]))].append((r_idx,change)) return change_points ##get boundaries and plot boundaries=getBoundaries(np.argmax(rgb,axis=0)) for bound in boundaries.values(): ax.RGB.plot([xxL[b] for b in bound],[yyL[b] for b in bound],'k',ls='-',lw=3) ##add contour lines for polyomino abundance on each colour channel for i,(channel,ax_c) in enumerate(zip(rgb,[ax.R,ax.G,ax.B])): ax_c.contour(channel, levels=20, colors='dimgrey',linewidths=.5, origin='lower',extent=[low,high]*2) if called: return ax plt.show(block=False)
def demo_rgb1(): fig = plt.figure() ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0) r, g, b = get_rgb() ax.imshow_rgb(r, g, b)
Z[Z < 0] = 0. Z = Z / Z.max() R = Z[:13, :13] G = Z[2:, 2:] B = Z[:13, 2:] return R, G, B fig = plt.figure(1) ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8]) r, g, b = get_rgb() kwargs = dict(origin="lower", interpolation="nearest") ax.imshow_rgb(r, g, b, **kwargs) ax.RGB.set_xlim(0., 9.5) ax.RGB.set_ylim(0.9, 10.6) plt.show() ############################################################################# # # ------------ # # References # """""""""" # # The use of the following functions, methods, classes and modules is shown # in this example:
Z[Z < 0] = 0. Z = Z / Z.max() R = Z[:13, :13] G = Z[2:, 2:] B = Z[:13, 2:] return R, G, B fig = plt.figure() ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8]) r, g, b = get_rgb() ax.imshow_rgb(r, g, b, origin="lower") ax.RGB.set_xlim(0., 9.5) ax.RGB.set_ylim(0.9, 10.6) plt.show() ############################################################################# # # .. admonition:: References # # The use of the following functions, methods, classes and modules is shown # in this example: # # - `mpl_toolkits.axes_grid1.axes_rgb.RGBAxes` # - `mpl_toolkits.axes_grid1.axes_rgb.RGBAxes.imshow_rgb`
Z = (Z1 - Z2) * 10 return Z, extent def get_rgb(): Z, extent = get_demo_image() Z[Z < 0] = 0. Z = Z / Z.max() R = Z[:13, :13] G = Z[2:, 2:] B = Z[:13, 2:] return R, G, B fig = plt.figure(1) ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8]) r, g, b = get_rgb() kwargs = dict(origin="lower", interpolation="nearest") ax.imshow_rgb(r, g, b, **kwargs) ax.RGB.set_xlim(0., 9.5) ax.RGB.set_ylim(0.9, 10.6) plt.draw() plt.show()
def test_RGB(T): plt.close('all') rgb = getRGB(T) fig = plt.figure() ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8]) ax.imshow_rgb(rgb[0], rgb[1], rgb[2])
import skimage import numpy as np import pylab as pl import matplotlib.pyplot as plt import astropy.io.fits as fits from scipy import ndimage as ndi from skimage import feature from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes from skimage.filters import roberts fig = plt.figure() ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8]) dat = fits.open('cutout_6.9276_22.0952.fits')[0].data print(max) r = dat[2, :, :] g = dat[1, :, :] b = dat[0, :, :] g[:, :] = 0.0 b[:, :] = 0.0 ax.imshow_rgb(r, g, b) pl.savefig('edges.pdf')
y_coeff = 0.2#0.14# l_coeff = np.array([[m_coeff, g_coeff], [c_coeff, y_coeff], [g_coeff, m_coeff], [c_coeff, y_coeff]]) y_frame = fill_masked_frame(raw_frame * np.tile(l_coeff, (int(580/4),int(752/2)))) / 65535.0 #magenta_frame *= 0.5 #cyan_frame *= 0.9 #yellow_frame *= 0.5 #green_frame *= 1.0 #y_frame = magenta_frame * m_coeff + cyan_frame * c_coeff + yellow_frame *y_coeff + green_frame * g_coeff u_frame = (magenta_frame + cyan_frame - green_frame - yellow_frame) * 0.5 v_frame = (magenta_frame + yellow_frame - green_frame - cyan_frame) * 0.5 r_frame = y_frame + 1.14 * v_frame g_frame = y_frame - 0.345 * u_frame - 0.581 * v_frame b_frame = y_frame + 2.032 * u_frame print ("Max Y = ", np.max(y_frame), "Min Y = ", np.min(y_frame)) print ("Max U = ", np.max(u_frame), "Min U = ", np.min(u_frame)) print ("Max V = ", np.max(v_frame), "Min V = ", np.min(v_frame)) print ("Max R = ", np.max(r_frame), "Min R = ", np.min(r_frame)) print ("Max G = ", np.max(g_frame), "Min G = ", np.min(g_frame)) print ("Max B = ", np.max(b_frame), "Min B = ", np.min(b_frame)) # # Plot the result # #plt.figure() #plt.imshow(raw_frame, origin="lower") ax = RGBAxes(plt.figure(), [0.0, 0.0, 1.0, 1.0]) ax.imshow_rgb(r_frame, g_frame * 1.5, b_frame, origin="lower", interpolation="nearest") plt.show()