Python matplotlib.cm.RdYlGn() Examples

The following are 17 code examples for showing how to use matplotlib.cm.RdYlGn(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may want to check out the right sidebar which shows the related API usage.

You may also want to check out all available functions/classes of the module matplotlib.cm , or try the search function .

Example 1
Project: opticspy   Author: Sterncat   File: asphere.py    License: MIT License 6 votes vote down vote up
def aspheresurface(self):
		"""
		Show the surface of an asphere.
		=============================================================
		Try: 
		A = opticspy.asphere.Coefficient(R=50,a2=0.18*10**(-8),a3 = 0.392629*10**(-13))

		"""
		R = self.__coefficients__[0]
		theta = __np__.linspace(0, 2*__np__.pi, 100)
		rho = __np__.linspace(0, R, 100)
		[u,r] = __np__.meshgrid(theta,rho)
		X = r*__cos__(u)
		Y = r*__sin__(u)
		Z = __aspherepolar__(self.__coefficients__,r)
		fig = __plt__.figure(figsize=(12, 8), dpi=80)
		ax = fig.gca(projection='3d')
		surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=__cm__.RdYlGn,
	        linewidth=0, antialiased=False, alpha = 0.6)
		__plt__.show()
		return 0 
Example 2
Project: opticspy   Author: Sterncat   File: asphere.py    License: MIT License 6 votes vote down vote up
def aspherematrix(self):
		l = 100
		R = self.__coefficients__[0]
		x1 = __np__.linspace(-R, R, l)
		[X,Y] = __np__.meshgrid(x1,x1)
		r = __sqrt__(X**2+Y**2)
		Z = __aspherepolar__(self.__coefficients__,r)
		for i in range(l):
			for j in range(l):
				if x1[i]**2+x1[j]**2 > R**2:
					Z[i][j] = 0
		fig = __plt__.figure(figsize=(12, 8), dpi=80)
		ax = fig.gca(projection='3d')
		surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=__cm__.RdYlGn,
	        linewidth=0, antialiased=False, alpha = 0.6)
		__plt__.show()
		return Z 
Example 3
Project: opticspy   Author: Sterncat   File: zernike_rec.py    License: MIT License 6 votes vote down vote up
def psf(self,lambda_1=632*10**(-9),z=0.1):
		"""
		------------------------------------------------
		psf()

		Return the point spread function of a wavefront described by
		Orthonormal Rectangular Polynomials
		------------------------------------------------
		Input: 

		r: exit pupil radius(mm)

		lambda_1: wavelength(m)

		z: exit pupil to image plane distance(m)

		"""
		PSF = self.__psfcaculator__(lambda_1=lambda_1,z=z)
		fig = __plt__.figure(figsize=(9, 6), dpi=80)
		__plt__.imshow(abs(PSF),cmap=__cm__.RdYlGn)
		__plt__.colorbar()
		__plt__.show()
		return 0 
Example 4
Project: opticspy   Author: Sterncat   File: zernike.py    License: MIT License 6 votes vote down vote up
def psf(self,r=1,lambda_1=632*10**(-9),z=0.1):
		"""
		------------------------------------------------
		psf()

		Return the point spread function of a wavefront described by
		Zernike Polynomials
		------------------------------------------------
		Input:

		r: exit pupil radius(mm)

		lambda_1: wavelength(m)

		z: exit pupil to image plane distance(m)

		"""
		print(r,lambda_1,z)
		PSF = self.__psfcaculator__(r=r,lambda_1=lambda_1,z=z)
		fig = __plt__.figure(figsize=(9, 6), dpi=80)
		__plt__.imshow(abs(PSF),cmap=__cm__.RdYlGn)
		__plt__.colorbar()
		__plt__.show()
		return 0 
Example 5
Project: opticspy   Author: Sterncat   File: seidel.py    License: MIT License 5 votes vote down vote up
def seidelsurface(self, label = True, zlim=[], matrix = False):
		r1 = __np__.linspace(0, 1, 100)
		u1 = __np__.linspace(0, 2*__np__.pi, 100)
		[u,r] = __np__.meshgrid(u1,r1)
		X = r*__cos__(u)
		Y = r*__sin__(u)
		W = __seidelpolar__(self.__coefficients__,r,u)
		fig = __plt__.figure(figsize=(12, 8), dpi=80)
		ax = fig.gca(projection='3d')
		surf = ax.plot_surface(X, Y, W, rstride=1, cstride=1, cmap=__cm__.RdYlGn,
	        linewidth=0, antialiased=False, alpha = 0.6)
		fig.colorbar(surf, shrink=1, aspect=30)
		__plt__.show() 
Example 6
Project: opticspy   Author: Sterncat   File: zernike_rec.py    License: MIT License 5 votes vote down vote up
def zernikesurface(self):
		"""
		------------------------------------------------
		zernikesurface(self, label_1 = True):

		Return a 3D Zernike Polynomials surface figure

		label_1: default show label

		------------------------------------------------
		"""
		a = self.__a__
		b = __sqrt__(1-a**2)
		x1 = __np__.linspace(-a, a, 50)
		y1 = __np__.linspace(-b, b, 50)
		[X,Y] = __np__.meshgrid(x1,y1)
		Z = __zernikecartesian__(self.__coefficients__,a,X,Y)
		fig = __plt__.figure(figsize=(12, 8), dpi=80)
		ax = fig.gca(projection='3d')
		surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=__cm__.RdYlGn,
	        linewidth=0, antialiased=False, alpha = 0.6)

		ax.auto_scale_xyz([-1, 1], [-1, 1], [Z.max(), Z.min()])
		# ax.set_xlim(-a, a)
		# ax.set_ylim(-b, b)
		# v = max(abs(Z.max()),abs(Z.min()))
		# ax.set_zlim(-v*5, v*5)
		# cset = ax.contourf(X, Y, Z, zdir='z', offset=-v*5, cmap=__cm__.RdYlGn)

		# ax.zaxis.set_major_locator(__LinearLocator__(10))
		# ax.zaxis.set_major_formatter(__FormatStrFormatter__('%.02f'))
		fig.colorbar(surf, shrink=1, aspect=30)

		# p2v = round(__tools__.peak2valley(Z),5)
		# rms1 = round(__tools__.rms(Z),5)
		__plt__.show() 
Example 7
Project: opticspy   Author: Sterncat   File: zernike.py    License: MIT License 5 votes vote down vote up
def zernikemap(self, label = True):
		"""
		------------------------------------------------
		zernikemap(self, label_1 = True):

		Return a 2D Zernike Polynomials map figure

		label: default show label

		------------------------------------------------
		"""


		theta = __np__.linspace(0, 2*__np__.pi, 400)
		rho = __np__.linspace(0, 1, 400)
		[u,r] = __np__.meshgrid(theta,rho)
		X = r*__cos__(u)
		Y = r*__sin__(u)
		Z = __interferometer__.__zernikepolar__(self.__coefficients__,r,u)
		fig = __plt__.figure(figsize=(12, 8), dpi=80)
		ax = fig.gca()
		im = __plt__.pcolormesh(X, Y, Z, cmap=__cm__.RdYlGn)

		if label == True:
			__plt__.title('Zernike Polynomials Surface Heat Map',fontsize=18)
			ax.set_xlabel(self.listcoefficient()[1],fontsize=18)
		__plt__.colorbar()
		ax.set_aspect('equal', 'datalim')
		__plt__.show() 
Example 8
Project: opticspy   Author: Sterncat   File: zernike.py    License: MIT License 5 votes vote down vote up
def __psfcaculator__(self,r=1,lambda_1=632*10**(-9),z=0.1):
		"""
		pupil: Exit pupil diameter
		z: Distance from exit pupil to image plane
		r: pupil radius, in unit of lambda
		"""
		pupil = l1 = 200 # exit pupil sample points
		x = __np__.linspace(-r, r, l1)
		[X,Y] = __np__.meshgrid(x,x)
		Z = __interferometer__.__zernikecartesian__(self.__coefficients__,X,Y)
		for i in range(len(Z)):
			for j in range(len(Z)):
				if x[i]**2+x[j]**2>r**2:
					Z[i][j] = 0
		d = 400 # background
		A = __np__.zeros([d,d])
		A[d//2-l1//2+1:d//2+l1//2+1,d//2-l1//2+1:d//2+l1//2+1] = Z
		axis_1 = d//pupil*r
		fig = __plt__.figure()
		# ax = fig.gca()
		# __plt__.imshow(A,extent=[-axis_1,axis_1,-axis_1,axis_1],cmap=__cm__.RdYlGn)
		# ax.set_xlabel('mm',fontsize=14)
		# __plt__.colorbar()
		# __plt__.show()

		abbe = __np__.exp(-1j*2*__np__.pi*A)
		for i in range(len(abbe)):
			for j in range(len(abbe)):
				if abbe[i][j]==1:
					abbe[i][j]=0
		PSF = __fftshift__(__fft2__(__fftshift__(abbe)))**2
		PSF = PSF/PSF.max()
		return PSF 
Example 9
Project: opticspy   Author: Sterncat   File: seidel2.py    License: MIT License 5 votes vote down vote up
def seidelsurface(self, label = True, zlim=[], matrix = False):
		r1 = __np__.linspace(0, 1, 100)
		u1 = __np__.linspace(0, 2*__np__.pi, 100)
		[u,r] = __np__.meshgrid(u1,r1)
		X = r*__cos__(u)
		Y = r*__sin__(u)
		W = __seidelpolar__(self.__coefficients__,r,u)
		fig = __plt__.figure(figsize=(12, 8), dpi=80)
		ax = fig.gca(projection='3d')
		surf = ax.plot_surface(X, Y, W, rstride=1, cstride=1, cmap=__cm__.RdYlGn,
	        linewidth=0, antialiased=False, alpha = 0.6)
		fig.colorbar(surf, shrink=1, aspect=30)
		__plt__.show() 
Example 10
Project: opticspy   Author: Sterncat   File: test_surface.py    License: MIT License 5 votes vote down vote up
def spherical_surf(l1):
	R = 1.02
	l1 = l1  #surface matrix length
	theta = __np__.linspace(0, 2*__np__.pi, l1)
	rho = __np__.linspace(0, 1, l1)
	[u,r] = __np__.meshgrid(theta,rho)
	X = r*__cos__(u)
	Y = r*__sin__(u)
	Z = __sqrt__(R**2-r**2)-__sqrt__(R**2-1)
	v_1 = max(abs(Z.max()),abs(Z.min()))

	noise = (__np__.random.rand(len(Z),len(Z))*2-1)*0.05*v_1
	Z = Z+noise
	fig = __plt__.figure(figsize=(12, 8), dpi=80)
	ax = fig.gca(projection='3d')
	surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=__cm__.RdYlGn,\
								linewidth=0, antialiased=False, alpha = 0.6)
	v = max(abs(Z.max()),abs(Z.min()))
	ax.set_zlim(-1, 2)
	ax.zaxis.set_major_locator(__LinearLocator__(10))
	ax.zaxis.set_major_formatter(__FormatStrFormatter__('%.02f'))
	cset = ax.contourf(X, Y, Z, zdir='z', offset=-1, cmap=__cm__.RdYlGn)
	fig.colorbar(surf, shrink=1, aspect=30)
	__plt__.title('Test Surface: Spherical surface with some noise',fontsize=16)
	__plt__.show()

	#Generate test surface matrix from a detector
	x = __np__.linspace(-1, 1, l1)
	y = __np__.linspace(-1, 1, l1)
	[X,Y] = __np__.meshgrid(x,y)
	Z = __sqrt__(R**2-(X**2+Y**2))-__sqrt__(R**2-1)+noise
	for i in range(len(Z)):
		for j in range(len(Z)):
			if x[i]**2+y[j]**2>1:
				Z[i][j]=0
	return Z 
Example 11
Project: opticspy   Author: Sterncat   File: hartmann.py    License: MIT License 5 votes vote down vote up
def hartmann_rebuild(M,r):
	s = len(M)
	w = __np__.zeros([s,s])
	d = 2
	for n in range(s):
		label = 0
		for m in range(s):
			if M[n][m][0] == 0:
				pass
			elif (M[n][m][0] != 0 and label == 0):
				w[n,m] = 0
				label = 1
			elif (M[n][m][0] != 0 and label == 1):
				w[n,m] = w[n][m-1] + d/2/r*(M[n][m-1][2][0] + M[n][m][2][0])
			else:
				print('wrong')
	fig = __plt__.figure(2,figsize=(6, 6))
	__plt__.imshow(w)
	__plt__.show()
	# x = __np__.linspace(-1,1,s)
	# [X,Y] = __np__.meshgrid(x,x)
	# fig = __plt__.figure(figsize=(8, 8), dpi=80)
	# ax = fig.gca(projection='3d')
	# surf = ax.plot_surface(w, rstride=1, cstride=1, cmap=__cm__.RdYlGn,
	#         linewidth=0, antialiased=False, alpha = 0.6)
	# __plt__.show()

	return w


#Depth first search algorithm, use to find wavefrontase map(where) 
Example 12
Project: Odin   Author: JamesBrofos   File: visualizer.py    License: MIT License 5 votes vote down vote up
def monthly_returns(self, fund, ax=None):
        if ax is None:
            ax = plt.gca()

        # Compute the returns on a month-over-month basis.
        history = fund.history
        monthly_ret = self.__aggregate_returns(history, 'monthly')
        monthly_ret = monthly_ret.unstack()
        monthly_ret = np.round(monthly_ret, 3)
        monthly_ret.rename(
            columns={1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr',
                     5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug',
                     9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec'},
            inplace=True
        )

        # Create a heatmap showing the month-over-month returns of the portfolio
        # or the fund.
        sns.heatmap(
            monthly_ret.fillna(0) * 100.0, annot=True, fmt="0.1f",
            annot_kws={"size": 12}, alpha=1.0, center=0.0, cbar=False,
            cmap=cm.RdYlGn, ax=ax
        )
        ax.set_title('Monthly Returns (%)', fontweight='bold')
        ax.set_ylabel('')
        ax.set_yticklabels(ax.get_yticklabels(), rotation=0)
        ax.set_xlabel('')

        return ax 
Example 13
Project: qstrader   Author: mhallsmoore   File: tearsheet.py    License: MIT License 5 votes vote down vote up
def _plot_monthly_returns(self, stats, ax=None, **kwargs):
        """
        Plots a heatmap of the monthly returns.
        """
        returns = stats['returns']
        if ax is None:
            ax = plt.gca()

        monthly_ret = perf.aggregate_returns(returns, 'monthly')
        monthly_ret = monthly_ret.unstack()
        monthly_ret = np.round(monthly_ret, 3)
        monthly_ret.rename(
            columns={1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr',
                     5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug',
                     9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec'},
            inplace=True
        )

        sns.heatmap(
            monthly_ret.fillna(0) * 100.0,
            annot=True,
            fmt="0.1f",
            annot_kws={"size": 8},
            alpha=1.0,
            center=0.0,
            cbar=False,
            cmap=cm.RdYlGn,
            ax=ax, **kwargs)
        ax.set_title('Monthly Returns (%)', fontweight='bold')
        ax.set_ylabel('')
        ax.set_yticklabels(ax.get_yticklabels(), rotation=0)
        ax.set_xlabel('')

        return ax 
Example 14
Project: qstrader   Author: quantstart   File: tearsheet.py    License: MIT License 5 votes vote down vote up
def _plot_monthly_returns(self, stats, ax=None, **kwargs):
        """
        Plots a heatmap of the monthly returns.
        """
        returns = stats['returns']
        if ax is None:
            ax = plt.gca()

        monthly_ret = perf.aggregate_returns(returns, 'monthly')
        monthly_ret = monthly_ret.unstack()
        monthly_ret = np.round(monthly_ret, 3)
        monthly_ret.rename(
            columns={1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr',
                     5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug',
                     9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec'},
            inplace=True
        )

        sns.heatmap(
            monthly_ret.fillna(0) * 100.0,
            annot=True,
            fmt="0.1f",
            annot_kws={"size": 8},
            alpha=1.0,
            center=0.0,
            cbar=False,
            cmap=cm.RdYlGn,
            ax=ax, **kwargs)
        ax.set_title('Monthly Returns (%)', fontweight='bold')
        ax.set_ylabel('')
        ax.set_yticklabels(ax.get_yticklabels(), rotation=0)
        ax.set_xlabel('')

        return ax 
Example 15
Project: opticspy   Author: Sterncat   File: interferometer_zenike.py    License: MIT License 4 votes vote down vote up
def rebuild_surface(data, shifttype = "4-step", unwraptype = "unwrap2D", noise = True):
	"""
	Rebuild surface function
	============================================
	input
	--------------------------------------------
	data: Interferogram data from PSI
	shifttype: PSI type, default 4-step PSI
	unwraptype: phaseunwrap type, default "simple"

	output
	--------------------------------------------
	rebuild surface matrix
	"""
	if shifttype == "4-step" and unwraptype == "simple" and noise == False:
		I = data[0]
		PR = data[1]
		ph = __np__.arctan2((I[3]-I[1]),(I[0]-I[2]))
		fig = __plt__.figure(figsize=(9, 6), dpi=80)
		im = __plt__.imshow(ph,extent=[-PR,PR,-PR,PR],cmap=__cm__.RdYlGn)
		__plt__.title('Wrapped phase',fontsize=16)
		__plt__.colorbar()
		__plt__.show()
		#-----------------------Phase unwrap-------------------------
		rebuild_ph = __unwrap2D__(ph,type = "simple")
		rebuild_surface = rebuild_ph/2/__np__.pi*PR/2
		#------------------------------------------------------------
		fig = __plt__.figure(figsize=(9, 6), dpi=80)
		im = __plt__.imshow(rebuild_surface,extent=[-PR,PR,-PR,PR],cmap=__cm__.RdYlGn)
		__plt__.title('Rebuild Surface',fontsize=16)
		__plt__.colorbar()
		__plt__.show()
		return rebuild_surface

	elif shifttype == "4-step" and unwraptype == "unwrap2D" and noise == True:
		I = data[0]
		PR = data[1]
		M = data[2]
		s = data[3]
		r = __np__.linspace(-PR, PR, s)
		ph = __np__.arctan2((I[3]-I[1]),(I[0]-I[2]))
		fig = __plt__.figure(figsize=(9, 6), dpi=80)
		im = __plt__.imshow(ph,extent=[-PR,PR,-PR,PR],cmap=__cm__.RdYlGn)
		__plt__.title('Wrapped phase',fontsize=16)
		__plt__.colorbar()
		__plt__.show()
		#-----------------------Phase unwrap-------------------------
		ph1 = [ph,M,s]
		rebuild_ph = __unwrap2D__(ph1,noise = True)
		rebuild_surface = rebuild_ph/2/__np__.pi*PR/2
		__tools__.makecircle_boundary(rebuild_surface, r, PR, 0)
		fig = __plt__.figure(figsize=(9, 6), dpi=80)
		im = __plt__.imshow(rebuild_surface,extent=[-PR,PR,-PR,PR],cmap=__cm__.RdYlGn)
		__plt__.title('Rebuild Surface',fontsize=16)
		__plt__.colorbar()
		__plt__.show()
		return rebuild_surface

	else:
		print("No this kind of phase shift type")
		return 0 
Example 16
Project: opticspy   Author: Sterncat   File: zernike.py    License: MIT License 4 votes vote down vote up
def zernikesurface(self, label = True, zlim=[], matrix = False):
		"""
		------------------------------------------------
		zernikesurface(self, label_1 = True):

		Return a 3D Zernike Polynomials surface figure

		label_1: default show label

		------------------------------------------------
		"""
		theta = __np__.linspace(0, 2*__np__.pi, 100)
		rho = __np__.linspace(0, 1, 100)
		[u,r] = __np__.meshgrid(theta,rho)
		X = r*__cos__(u)
		Y = r*__sin__(u)
		Z = __interferometer__.__zernikepolar__(self.__coefficients__,r,u)
		fig = __plt__.figure(figsize=(12, 8), dpi=80)
		ax = fig.gca(projection='3d')
		surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=__cm__.RdYlGn,
	        linewidth=0, antialiased=False, alpha = 0.6)

		if zlim == []:
			v = max(abs(Z.max()),abs(Z.min()))
			ax.set_zlim(-v*5, v*5)
			cset = ax.contourf(X, Y, Z, zdir='z', offset=-v*5, cmap=__cm__.RdYlGn)
		else:
			ax.set_zlim(zlim[0], zlim[1])
			cset = ax.contourf(X, Y, Z, zdir='z', offset=zlim[0], cmap=__cm__.RdYlGn)

		ax.zaxis.set_major_locator(__LinearLocator__(10))
		ax.zaxis.set_major_formatter(__FormatStrFormatter__('%.02f'))
		fig.colorbar(surf, shrink=1, aspect=30)


		p2v = round(__tools__.peak2valley(Z),5)
		rms1 = round(__tools__.rms(Z),5)

		label_1 = self.listcoefficient()[0]+"P-V: "+str(p2v)+"\n"+"RMS: "+str(rms1)
		if label == True:
			__plt__.title('Zernike Polynomials Surface',fontsize=18)
			ax.text2D(0.02, 0.1, label_1, transform=ax.transAxes,fontsize=14)
		else:
			pass
		__plt__.show()

		if matrix == True:
			return Z
		else:
			pass 
Example 17
Project: jqfactor_analyzer   Author: JoinQuant   File: plotting.py    License: MIT License 4 votes vote down vote up
def plot_monthly_ic_heatmap(mean_monthly_ic, ax=None):

    mean_monthly_ic = mean_monthly_ic.copy()

    num_plots = len(mean_monthly_ic.columns)

    v_spaces = ((num_plots - 1) // 3) + 1

    if ax is None:
        f, ax = plt.subplots(v_spaces, 3, figsize=(18, v_spaces * 6))
        ax = ax.flatten()

    new_index_year = []
    new_index_month = []
    for date in mean_monthly_ic.index:
        new_index_year.append(date.year)
        new_index_month.append(date.month)

    mean_monthly_ic.index = pd.MultiIndex.from_arrays(
        [new_index_year, new_index_month], names=["year", "month"]
    )

    for a, (period, ic) in zip(ax, mean_monthly_ic.iteritems()):
        periods_num = period.replace('period_', '')

        sns.heatmap(
            ic.unstack(),
            annot=True,
            alpha=1.0,
            center=0.0,
            annot_kws={"size": 15},
            linewidths=0.01,
            linecolor='white',
            cmap=cm.RdYlGn,
            cbar=False,
            ax=a
        )
        a.set(ylabel='', xlabel='')
        a.set_title(ICHEATMAP.get("TITLE").format(periods_num))

    if num_plots < len(ax):
        for a in ax[num_plots:]:
            a.set_visible(False)

    return ax