本文整理汇总了Python中matplotlib.pyplot.pcolor函数的典型用法代码示例。如果您正苦于以下问题:Python pcolor函数的具体用法?Python pcolor怎么用?Python pcolor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pcolor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visual
def visual(self,vtype=None):
if vtype==None:
print(self)
elif vtype=="syn":
tempmat=np.matrix(np.zeros((self._M,self._W)))
synvec=[]
for i in range(0,self._M):
synvec.append(len(self.get_known_words(i)))
for j in range(0,self._W):
tempmat[i,j]=(self._W-synvec[i]+1)*self._content[i,j]
plt.title("Synonymy")
plt.xlabel("Words")
plt.ylabel("Meanings")
plt.gca().invert_yaxis()
plt.pcolor(np.array(tempmat),vmin=0,vmax=self._W)
elif vtype=="hom":
tempmat=np.matrix(np.zeros((self._M,self._W)))
homvec=[]
for j in range(0,self._W):
homvec.append(len(self.get_known_meanings(j)))
for i in range(0,self._M):
tempmat[i,j]=(self._M-homvec[j]+1)*self._content[i,j]
plt.title("Homonymy")
plt.xlabel("Words")
plt.ylabel("Meanings")
plt.gca().invert_yaxis()
plt.pcolor(np.array(tempmat),vmin=0,vmax=self._M)
示例2: create_subheatmap
def create_subheatmap(intensity, job, host, n, num_hosts):
"""
Creates a heatmap in a subplot.
Arguments:
intensity -- the values of the intensity being plotted. Must be same length as job.times
job -- the current job being plotted
host -- the host being charted
n -- the subplot number of the specific host
num_hosts -- the total number of hosts to be plotted
"""
length = job.times.size
end = job.end_time
start = job.start_time
x = NP.linspace(0, (end - start) / 3600.0, length * 1)
intensity = NP.array([intensity]*2, dtype=NP.float64)
PLT.subplot(num_hosts+1, 1, n)
PLT.pcolor(x, NP.array([0, 1]), intensity, cmap=matplotlib.cm.Reds, vmin = 0, vmax = math.ceil(NP.max(intensity)), edgecolors='none')
if (n != num_hosts):
PLT.xticks([])
else:
PLT.xlabel('Hours From Job Beginning')
PLT.yticks([])
#PLT.autoscale(enable=True,axis='both',tight=True)
host_name = host.replace('.tacc.utexas.edu', '')
PLT.ylabel(host_name, fontsize ='small', rotation='horizontal')
示例3: image
def image(self, point_grid=None, cmap='hot'):
"""
makes an image of the (2-dimensional) x and predicted y
Input:
point_grid:
a grid constructed with mgrid[...]
tuple (max_x0, max_x1) specifying the grid mgrid[0:max_x0:100j, 0:max_x1:100j]
defaults to mgrid[0:max(x[:,0]):100j, 0:max(x[:,1]):100j]
"""
if point_grid is None:
point_grid = self.mk_grid('minmax')
elif isinstance(point_grid, tuple):
point_grid = self.mk_grid(point_grid)
n_xgrid = shape(point_grid)[1]
n_ygrid = shape(point_grid)[2]
positions = vstack(map(ravel, point_grid)).transpose()
plt.pcolor(positions[:, 0].reshape(n_xgrid, n_ygrid),
positions[:, 1].reshape(n_xgrid, n_ygrid),
self.predict_proba(positions)[:, 1]
.reshape(n_xgrid, n_ygrid), cmap=cmap)
plt.tight_layout()
plt.colorbar()
plt.xlabel(self.x_name[0])
plt.ylabel(self.x_name[1])
plt.title(self.y_prob_name)
示例4: test_complete
def test_complete():
fig = plt.figure('Figure with a label?', figsize=(10, 6))
plt.suptitle('Can you fit any more in a figure?')
# make some arbitrary data
x, y = np.arange(8), np.arange(10)
data = u = v = np.linspace(0, 10, 80).reshape(10, 8)
v = np.sin(v * -0.6)
plt.subplot(3, 3, 1)
plt.plot(list(xrange(10)))
plt.subplot(3, 3, 2)
plt.contourf(data, hatches=['//', 'ooo'])
plt.colorbar()
plt.subplot(3, 3, 3)
plt.pcolormesh(data)
plt.subplot(3, 3, 4)
plt.imshow(data)
plt.subplot(3, 3, 5)
plt.pcolor(data)
plt.subplot(3, 3, 6)
plt.streamplot(x, y, u, v)
plt.subplot(3, 3, 7)
plt.quiver(x, y, u, v)
plt.subplot(3, 3, 8)
plt.scatter(x, x**2, label='$x^2$')
plt.legend(loc='upper left')
plt.subplot(3, 3, 9)
plt.errorbar(x, x * -0.5, xerr=0.2, yerr=0.4)
###### plotting is done, now test its pickle-ability #########
# Uncomment to debug any unpicklable objects. This is slow (~200 seconds).
# recursive_pickle(fig)
result_fh = BytesIO()
pickle.dump(fig, result_fh, pickle.HIGHEST_PROTOCOL)
plt.close('all')
# make doubly sure that there are no figures left
assert_equal(plt._pylab_helpers.Gcf.figs, {})
# wind back the fh and load in the figure
result_fh.seek(0)
fig = pickle.load(result_fh)
# make sure there is now a figure manager
assert_not_equal(plt._pylab_helpers.Gcf.figs, {})
assert_equal(fig.get_label(), 'Figure with a label?')
示例5: plot_array
def plot_array(array, title):
'''Part 1: Plot an array using pcolor and title it'''
plt.ylim(0, array.shape[0])
plt.xlim(0, array.shape[1])
plt.pcolor(array, vmin=0, vmax=1) # 1/up=red, 0/down=blue
plt.title(title)
plt.show()
示例6: sorted_heatmap
def sorted_heatmap(weights):
"""Create a sorted heatmap.
Plot a matrix such that the biggest row/col values are in the upper left
of the heatmap.
Args:
weights - a 2d numpy array of floats
Returns:
A plot that can be saved to a file via plt.savefig('file')
"""
weights = weights.reshape(weights.shape[:2])
row_order = np.array(sorted(weights, key=lambda row: np.sum(row)))
col_order = np.array(sorted(row_order.T, key=lambda row: -np.sum(row))).T
cMap = plt.get_cmap("Blues")
fig1 = plt.figure(1)
fig1.add_subplot(1, 1, 1)
heatmap = plt.pcolor(col_order[:200, :200], cmap=cMap)
plt.colorbar(heatmap)
plt.title("Reviewer-Paper Affinities")
plt.xlabel("Paper")
plt.ylabel("Reviewer")
fig2 = plt.figure(2)
fig2.add_subplot(1, 1, 1)
heatmap = plt.pcolor(col_order[-200:, -200:], cmap=cMap)
plt.colorbar(heatmap)
plt.title("Reviewer-Paper Affinities")
plt.xlabel("Paper")
plt.ylabel("Reviewer")
return fig1, fig2
示例7: _colormap_plot_array_response
def _colormap_plot_array_response(cmaps):
"""
Plot for illustrating colormaps: array response.
:param cmaps: list of :class:`~matplotlib.colors.Colormap`
:rtype: None
"""
import matplotlib.pyplot as plt
from obspy.signal.array_analysis import array_transff_wavenumber
# generate array coordinates
coords = np.array([[10., 60., 0.], [200., 50., 0.], [-120., 170., 0.],
[-100., -150., 0.], [30., -220., 0.]])
# coordinates in km
coords /= 1000.
# set limits for wavenumber differences to analyze
klim = 40.
kxmin = -klim
kxmax = klim
kymin = -klim
kymax = klim
kstep = klim / 100.
# compute transfer function as a function of wavenumber difference
transff = array_transff_wavenumber(coords, klim, kstep, coordsys='xy')
# plot
for cmap in cmaps:
plt.figure()
plt.pcolor(np.arange(kxmin, kxmax + kstep * 1.1, kstep) - kstep / 2.,
np.arange(kymin, kymax + kstep * 1.1, kstep) - kstep / 2.,
transff.T, cmap=cmap)
plt.colorbar()
plt.clim(vmin=0., vmax=1.)
plt.xlim(kxmin, kxmax)
plt.ylim(kymin, kymax)
plt.show()
示例8: show_heatmap
def show_heatmap(self, component):
""" prints a quick simple heads up heatmap of input component of the mean_set attribute"""
fig, ax = plt.subplots()
plt.pcolor(self[component]) # see __getitem__
plt.colorbar()
plt.title(component)
plt.show()
示例9: nearest
def nearest(galaxies):
midRA = 334.37
midDec = 0.2425
peakLimit = 3.077
#put the positions of all galaxies into one array
positions = np.array([])
for gal in galaxies:
galaxy = galaxies[gal]
x = cmToMpc*DC(galaxy.z)*(galaxy.RA-midRA)*(np.pi/180.)
y = cmToMpc*DC(galaxy.z)*(galaxy.dec-midDec)*(np.pi/180.)
z = (cmToMpc*DC(galaxy.z)-cmToMpc*(DC(peakLimit)))
positions = np.append(positions, [x, y, z])
positions = np.reshape(positions, (-1, 3))
#create the map to save the data
nx = 100
ny = 100
xs = np.linspace(-8, 8, nx)
yx = np.linspace(-8, 8, ny)
map = np.zeros((nx, ny))
#loop through each of the positions in the map
for ix in range(nx):
for iy in range(ny):
xpositions = positions[:,0]
ypositions = positions[:,1]
zpositions = positions[:,2]
distances = np.sqrt((xpositions-xs[ix])**2+(ypositions-yx[iy])**2+(zpositions-peakLimit)**2)
print(min(distances))
map[ix,iy] = 1/(min(distances)+10)
plt.pcolor(map)
plt.show()
示例10: heatmap
def heatmap(df, cmap="OrRd", figsize=(10, 10)):
"""draw heatmap of df"""
plt.figure(figsize=figsize)
plt.xticks(np.arange(0.5, len(df.columns), 1), df.columns)
plt.yticks(np.arange(0.5, len(df.index), 1), df.index)
plt.pcolor(df, cmap=cmap)
示例11: solve
def solve(m, computeRhs, bcs, plot = False, filename = ''):
h = (1.0 - 0.0) / (m + 1.0)
x = np.linspace(0, 1, m + 2)
y = np.linspace(0, 1, m + 2)
X, Y = np.meshgrid(x, y)
matrix = getMatrix(m)
f = computeRhs(X[1:-1, 1:-1], Y[1:-1, 1:-1], bcs, h)
u = linalg.spsolve(matrix, f)
u=u.reshape([m,m])
sol = np.zeros((m+2, m+2))
sol[1:-1, 1:-1] = u
# Add boundary conditions values to solution.
sol[:, 0] = bcs['left'](y)
sol[:, -1] = bcs['right'](y)
sol[0, :] = bcs['bottom'](x)
sol[-1, :] = bcs['top'](x)
# Plot solution.
if plot:
import matplotlib.pyplot as plt
plt.clf()
plt.pcolor(X,Y,sol)
plt.colorbar()
plt.xlabel(r'$x$')
plt.ylabel(r'$y$')
if filename:
plt.savefig(filename)
plt.show()
return sol, X, Y
示例12: test_2d_iterp
def test_2d_iterp(self):
import numpy as np
from scipy.interpolate import Rbf
import matplotlib.pyplot as plt
from matplotlib import cm
# 2-d tests - setup scattered data
x = np.random.rand(3) * 4.0 - 2.0
y = np.random.rand(3) * 4.0 - 2.0
z = x * np.exp(-x ** 2 - y ** 2)
ti = np.linspace(-2.0, 2.0, 100)
XI, YI = np.meshgrid(ti, ti)
# use RBF
rbf = Rbf(x, y, z, epsilon=2)
ZI = rbf(XI, YI)
# plot the result
n = plt.Normalize(-2.0, 2.0)
plt.subplot(1, 1, 1)
plt.pcolor(XI, YI, ZI, cmap=cm.jet)
plt.scatter(x, y, 100, z, cmap=cm.jet)
plt.title("RBF interpolation - multiquadrics")
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.colorbar()
plt.show()
示例13: toImage
def toImage(self,func):
# do log
print func
func[func>self.para[1]] = np.log10(func[func>self.para[1]])
plt.pcolor(func,cmap = cm.cool)
plt.colorbar()
plt.show()
示例14: plot_zvsz
def plot_zvsz(z_phot, z_true, binning, z_min, z_max):
plt.figure(figsize=(13, 7))
plt.subplot(121)
plt.plot(z_true, z_phot, 'o', markersize = 1)
plt.plot([z_min, z_max], [z_min, z_max], linewidth = 1, color = 'red')
plt.axis('scaled')
plt.xlim(xmin = z_min, xmax = z_max)
plt.ylim(ymin = z_min, ymax = z_max)
plt.xlabel("z(true)")
plt.ylabel("z(phot)")
plt.subplot(122)
H = tool.migration_matrix(z_phot, z_true, binning)
H = H.T
plt.pcolor(binning, binning, H)
plt.axis('scaled')
plt.xlim(xmin = z_min, xmax = z_max)
plt.ylim(ymin = z_min, ymax = z_max)
plt.ylabel("z(phot)")
plt.xlabel("z(true)")
plt.title("Transition Matrix z(true)$\\rightarrow$z(phot)")
#plt.colorbar(aspect = 30, orientation = 'horitzontal', fraction = 0.03).set_label("Probability")
plt.colorbar(aspect = 30, fraction = 0.03).set_label("Probability")
plt.savefig(plot_folder + "zvsz.png", bbox_inches='tight')
#plt.savefig(plot_folder + "zvsz.pdf", bbox_inches='tight')
plt.close()
示例15: draw
def draw(self):
filename = self.filename
file = open(os.getcwd() + "\\" + filename, 'r')
lines = csv.reader(file)
#
data = []
x = []
y = []
z = []
for line in lines:
try:
data.append(line)
except Exception as e:
print e
pass
# print data
for i in range(1, len(data)):
try:
x.append(float(data[i][0]))
y.append(float(data[i][1]))
z.append(float(data[i][3]))
finally:
pass
xx = np.array(x)
yy = np.array(y)
zz = np.array(z)
# print np.min(xx)
tx = np.linspace(np.min(xx), np.max(xx), 100)
ty = np.linspace(np.min(yy), np.max(yy), 100)
XI, YI = np.meshgrid(tx, ty)
rbf = interpolate.Rbf(xx, yy, zz, epsilon=2)
ZI = rbf(XI, YI)
#
plt.gca().set_aspect(1.0)
font = font_manager.FontProperties(family='times new roman', style='italic', size=16)
cs = plt.contour(XI, YI, ZI, colors="black")
plt.clabel(cs, cs.levels, inline=True, fontsize=10, prop=font)
plt.subplot(1, 1, 1)
plt.pcolor(XI, YI, ZI, cmap=cm.jet)
plt.scatter(xx, yy, 100, zz, cmap=cm.jet)
plt.title('interpolation example')
plt.xlim(int(xx.min()), int(xx.max()))
plt.ylim(int(yy.min()), int(yy.max()))
plt.colorbar()
plt.savefig("interpolation.jpg")
#plt.show()
return ZI, XI, YI