本文整理匯總了Python中matplotlib.pyplot.tripcolor方法的典型用法代碼示例。如果您正苦於以下問題:Python pyplot.tripcolor方法的具體用法?Python pyplot.tripcolor怎麽用?Python pyplot.tripcolor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.tripcolor方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cortex_cmap_plot_2D
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def cortex_cmap_plot_2D(the_map, zs, cmap, vmin=None, vmax=None, axes=None, triangulation=None):
'''
cortex_cmap_plot_2D(map, zs, cmap, axes) plots the given cortical map values zs on the given
axes using the given given color map and yields the resulting polygon collection object.
cortex_cmap_plot_2D(map, zs, cmap) uses matplotlib.pyplot.gca() for the axes.
The following options may be passed:
* triangulation (None) may specify the triangularion object for the mesh if it has already
been created; otherwise it is generated fresh.
* axes (None) specify the axes on which to plot; if None, then matplotlib.pyplot.gca() is
used. If Ellipsis, then a tuple (triangulation, z, cmap) is returned; to recreate the plot,
one would call:
axes.tripcolor(triangulation, z, cmap, shading='gouraud', vmin=vmin, vmax=vmax)
* vmin (default: None) specifies the minimum value for scaling the property when one is passed
as the color option. None means to use the min value of the property.
* vmax (default: None) specifies the maximum value for scaling the property when one is passed
as the color option. None means to use the max value of the property.
'''
if triangulation is None:
triangulation = matplotlib.tri.Triangulation(the_map.coordinates[0], the_map.coordinates[1],
triangles=the_map.tess.indexed_faces.T)
if axes is Ellipsis: return (triangulation, zs, cmap)
return axes.tripcolor(triangulation, zs, cmap=cmap, shading='gouraud', vmin=vmin, vmax=vmax)
示例2: draw_nodal_values_shaded
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def draw_nodal_values_shaded(values, coords, edof, title=None, dofs_per_node=None, el_type=None, draw_elements=False):
"""Draws element nodal values as shaded triangles. Element topologies
supported are triangles, 4-node quads and 8-node quads."""
edof_tri = topo_to_tri(edof)
ax = plt.gca()
ax.set_aspect('equal')
x, y = coords.T
v = np.asarray(values)
plt.tripcolor(x, y, edof_tri - 1, v.ravel(), shading="gouraud")
if draw_elements:
if dofs_per_node != None and el_type != None:
draw_mesh(coords, edof, dofs_per_node,
el_type, color=(0.2, 0.2, 0.2))
else:
info("dofs_per_node and el_type must be specified to draw the mesh.")
if title != None:
ax.set(title=title)
示例3: test_tripcolor
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def test_tripcolor():
x = np.asarray([0, 0.5, 1, 0, 0.5, 1, 0, 0.5, 1, 0.75])
y = np.asarray([0, 0, 0, 0.5, 0.5, 0.5, 1, 1, 1, 0.75])
triangles = np.asarray([
[0, 1, 3], [1, 4, 3],
[1, 2, 4], [2, 5, 4],
[3, 4, 6], [4, 7, 6],
[4, 5, 9], [7, 4, 9], [8, 7, 9], [5, 8, 9]])
# Triangulation with same number of points and triangles.
triang = mtri.Triangulation(x, y, triangles)
Cpoints = x + 0.5*y
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
Cfaces = 0.5*xmid + ymid
plt.subplot(121)
plt.tripcolor(triang, Cpoints, edgecolors='k')
plt.title('point colors')
plt.subplot(122)
plt.tripcolor(triang, facecolors=Cfaces, edgecolors='k')
plt.title('facecolors')
示例4: test_pcolor_heatmap
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def test_pcolor_heatmap():
# import matplotlib.tri as tri
from matplotlib import pyplot as plt
mesh3D = mesh(100,edges=True)
mesh2D = proj_to_2D(mesh3D)
# triangulation = tri.Triangulation(mesh2D) # this is called in tripcolor
data = np.zeros((3,3))
data[0,1] += 1
vals = np.exp(log_dirichlet_density(mesh3D,2.,data=data.sum(0)))
temp = log_censored_dirichlet_density(mesh3D,2.,data=data)
censored_vals = np.exp(temp - temp.max())
plt.figure()
plt.tripcolor(mesh2D[:,0],mesh2D[:,1],vals)
plt.title('uncensored')
plt.figure()
plt.tripcolor(mesh2D[:,0],mesh2D[:,1],censored_vals)
plt.title('censored')
示例5: _plot_rgb_triangle
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def _plot_rgb_triangle(xy_to_2d, bright=True):
# plot sRGB triangle
# discretization points
n = 50
# Get all RGB values that sum up to 1.
rgb_linear, _ = meshzoo.triangle(n)
if bright:
# For the x-y-diagram, it doesn't matter if the values are scaled in any way.
# After all, the tranlation to XYZ is linear, and then to xyY it's (X/(X+Y+Z),
# Y/(X+Y+Z), Y), so the factor will only be present in the last component which
# is discarded. To make the plot a bit brighter, scale the colors up as much as
# possible.
rgb_linear /= numpy.max(rgb_linear, axis=0)
srgb_linear = SrgbLinear()
xyz = srgb_linear.to_xyz100(rgb_linear)
xyy_vals = xy_to_2d(_xyy_from_xyz100(xyz)[:2])
# Unfortunately, one cannot use tripcolors with explicit RGB specification
# (see <https://github.com/matplotlib/matplotlib/issues/10265>). As a
# workaround, associate range(n) data with the points and create a colormap
# that associates the integer values with the respective RGBs.
z = numpy.arange(xyy_vals.shape[1])
rgb = srgb_linear.to_srgb1(rgb_linear)
cmap = matplotlib.colors.LinearSegmentedColormap.from_list(
"gamut", rgb.T, N=len(rgb.T)
)
triang = matplotlib.tri.Triangulation(xyy_vals[0], xyy_vals[1])
plt.tripcolor(triang, z, shading="gouraud", cmap=cmap)
return
示例6: trace_roi
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def trace_roi(hemi, map_proj, axes, closed=True, event_handlers=None, plot_list=None, **kw):
'''
trace_roi(hemi, map_proj, axes) creates an ROIDrawer object that controls the tracing of lines
around an ROI in a 2D matplotlib plot and returns a not-yet-persistent immutable PathTrace
object with the ROIDrawer in its meta_data. The path trace is persisted as soon as the user
finished drawing their line; if the line is canceled, then the trace is never persisted.
ROI tracing is very simple: any point in the plot is appended to the path as it is clicked; in
order to eliminate the previous point, hold shift while clicking. To end the path, hold control
while clicking. To abort the path, hold both shift and control while clicking. (Double-clicking
should be equivalent to control-clicking, but this does not work in all setups.) In order to use
the ROI tracing, `%matplotlib notebook` is recommended.
The trace_roi() function accepts all options that can be passed to cortex_plot() as well as the
following options:
* closed (default: True) specifies whether the path-trace that is constructed should be closed
(True) or open (False).
* event_handlers (default: None) specifies additional event handlers (named by key) for the
ROIDrawer().
* plot_list (default: None) specifies a list of alternate TriMesh objects that can be plotted
cyclically when the user presses tab. TriMesh objects can be created by pyplot.triplot and
pyplot.tripcolor, which are used by the neuropythy cortex_plot function as well. If the
plot_list is not empty, then the first item of the list is immediately plotted on the axes.
Unlike in the ROIDrawer function itself, the plot_list may contain maps whose keys are
the various arguments (aside from the initial mesh argument) to cortex_plot.
'''
# okay, first off, if the plot_list has maps in it, we convert them using cortex_plot:
if plot_list is not None:
if geo.is_flatmap(hemi): fmap = hemi
elif geo.is_flatmap(map_proj): fmap = map_proj
elif not geo.is_map_projection(map_proj): fmap = geo.to_map_projection(map_proj)(hemi)
else: fmap = map_proj(hemi)
plot_list = [cortex_plot(fmap, axes=axes, **p) if pimms.is_map(p) else p
for p in plot_list]
# next, make the roi drawer
rd = ROIDrawer(axes, map_proj, closed=closed,
event_handlers=event_handlers, plot_list=plot_list)
return rd.trace
示例7: topo_to_tri
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def topo_to_tri(edof):
"""Converts 2d element topology to triangle topology to be used
with the matplotlib functions tricontour and tripcolor."""
if edof.shape[1] == 3:
return edof
elif edof.shape[1] == 4:
new_edof = np.zeros((edof.shape[0]*2, 3), int)
new_edof[0::2, 0] = edof[:, 0]
new_edof[0::2, 1] = edof[:, 1]
new_edof[0::2, 2] = edof[:, 2]
new_edof[1::2, 0] = edof[:, 2]
new_edof[1::2, 1] = edof[:, 3]
new_edof[1::2, 2] = edof[:, 0]
return new_edof
elif edof.shape[1] == 8:
new_edof = np.zeros((edof.shape[0]*6, 3), int)
new_edof[0::6, 0] = edof[:, 0]
new_edof[0::6, 1] = edof[:, 4]
new_edof[0::6, 2] = edof[:, 7]
new_edof[1::6, 0] = edof[:, 4]
new_edof[1::6, 1] = edof[:, 1]
new_edof[1::6, 2] = edof[:, 5]
new_edof[2::6, 0] = edof[:, 5]
new_edof[2::6, 1] = edof[:, 2]
new_edof[2::6, 2] = edof[:, 6]
new_edof[3::6, 0] = edof[:, 6]
new_edof[3::6, 1] = edof[:, 3]
new_edof[3::6, 2] = edof[:, 7]
new_edof[4::6, 0] = edof[:, 4]
new_edof[4::6, 1] = edof[:, 6]
new_edof[4::6, 2] = edof[:, 7]
new_edof[5::6, 0] = edof[:, 4]
new_edof[5::6, 1] = edof[:, 5]
new_edof[5::6, 2] = edof[:, 6]
return new_edof
else:
error("Element topology not supported.")
示例8: plot_many_gll
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def plot_many_gll(x, y, z, vmin=None, vmax=None):
""" Plots values on big 2D unstructured GLL mesh
(in that case tricontourf does not work)
"""
r = (max(x) - min(x))/(max(y) - min(y))
rx = r/np.sqrt(1 + r**2)
ry = 1/np.sqrt(1 + r**2)
f = plt.figure(figsize=(10*rx, 10*ry))
p = plt.tripcolor(x, y, z, vmin=vmin, vmax=vmax)
plt.axis('image')
return f, p
示例9: plot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def plot(self):
if self.__numberOfVertices != 3: raise RuntimeError('Plotting only supported in 2D')
matrix = self.testPoints[0:self.iterations, :]
x = matrix[:,0].flat
y = matrix[:,1].flat
z = matrix[:,2].flat
coords = []
acquisitions = []
for triangle in self.queue:
coords.append(triangle.pointIndices)
acquisitions.append(-1 * triangle.acquisitionValue)
plotter.figure()
plotter.tricontourf(x, y, coords, z)
plotter.triplot(x, y, coords, color='white', lw=0.5)
plotter.colorbar()
plotter.figure()
plotter.tripcolor(x, y, coords, acquisitions)
plotter.triplot(x, y, coords, color='white', lw=0.5)
plotter.colorbar()
plotter.show()
示例10: tri_plot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def tri_plot(tri, field, title="", levels=12, savefigs=False,
plt_type="contourf", filename="solution_plot.pdf"):
"""Plot contours over triangulation
Parameters
----------
tri : ndarray (float)
Array with number and nodes coordinates:
`number coordX coordY BCX BCY`
field : ndarray (float)
Array with data to be plotted for each node.
title : string (optional)
Title of the plot.
levels : int (optional)
Number of levels to be used in ``contourf``.
savefigs : bool (optional)
Allow to save the figure.
plt_type : string (optional)
Plot the field as one of the options: ``pcolor`` or
``contourf``
filename : string (optional)
Filename to save the figures.
"""
if plt_type == "pcolor":
disp_plot = plt.tripcolor
elif plt_type == "contourf":
disp_plot = plt.tricontourf
disp_plot(tri, field, levels, shading="gouraud")
plt.title(title)
plt.colorbar(orientation='vertical')
plt.axis("image")
if savefigs:
plt.savefig(filename)
示例11: cortex_plot_2D
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def cortex_plot_2D(the_map,
color=None, cmap=None, vmin=None, vmax=None, alpha=None,
underlay='curvature', mask=None, axes=None, triangulation=None):
'''
cortex_plot_2D(map) yields a plot of the given 2D cortical mesh, map.
The following options are accepted:
* color (default: None) specifies the color to plot for each vertex; this argument may take a
number of forms:
* None, do not plot a color over the underlay (the default)
* a matrix of RGB or RGBA values, one per vertex
* a property vector or a string naming a property, in which case the cmap, vmin, and vmax
arguments are used to generate colors
* a function that, when passed a single argument, a dict of the properties of a single
vertex, yields an RGB or RGBA list for that vertex.
* cmap (default: 'eccenflat') specifies the colormap to use in plotting if the color
argument provided is a property.
* vmin (default: None) specifies the minimum value for scaling the property when one is passed
as the color option. None means to use the min value of the property.
* vmax (default: None) specifies the maximum value for scaling the property when one is passed
as the color option. None means to use the max value of the property.
* underlay (default: 'curvature') specifies the default underlay color to plot for the
cortical surface; it may be None, 'curvature', or a color.
* alpha (default None) specifies the alpha values to use for the color plot. If None, then
leaves the alpha values from color unchanged. If a single number, then all alpha values in
color are multiplied by that value. If a list of values, one per vertex, then this vector
is multiplied by the alpha values. Finally, any negative value is set instead of multiplied.
So, for example, if there were 3 vertices with:
* color = ((0,0,0,1), (0,0,1,0.5), (0,0,0.75,0,8))
* alpha = (-0.5, 1, 0.5)
then the resulting colors plotted will be ((0,0,0,0.5), (0,0,1,0.5), (0,0,0.75,0,4)).
* mask (default: None) specifies a mask to use for the mesh; thi sis passed through map.mask()
to figure out the masking. Those vertices not in the mask are not plotted (but they will be
plotted in the underlay if it is not None).
* axes (default: None) specifies a particular set of matplotlib pyplot axes that should be
used. If axes is Ellipsis, then instead of attempting to render the plot, a tuple of
(tri, zs, cmap) is returned; in this case, tri is a matplotlib.tri.Triangulation
object for the given map and zs and cmap are an array and colormap (respectively) that
will produce the correct colors. Without axes equal to Ellipsis, these would instead
be rendered as axes.tripcolor(tri, zs, cmap, shading='gouraud'). If axes is None, then
uses the current axes.
* triangulation (default: None) specifies the matplotlib triangulation object to use, if one
already exists; otherwise a new one is made.
'''
# parse the axes
if axes is None: axes = matplotlib.pyplot.gca()
# process the colors
color = cortex_plot_colors(the_map, color=color, cmap=cmap, vmin=vmin, vmax=vmax, alpha=alpha,
underlay=underlay, mask=mask)
# finally, we can make the plot!
return cortex_rgba_plot_2D(the_map, color, axes=axes, triangulation=triangulation)
# 3D Graphics ######################################################################################
# If we're using Python 2, we're compatible with pysurfer:
示例12: cortex_plot
# 需要導入模塊: from matplotlib import pyplot [as 別名]
# 或者: from matplotlib.pyplot import tripcolor [as 別名]
def cortex_plot(mesh, *args, **opts):
'''
cortex_plot(mesh) calls either cortex_plot_2D or cortex_plot_3D depending on the dimensionality
of the given mesh, and yields the resulting graphics object. All optional arguments supported
by each is supported by cortex plot.
The following options are accepted:
* color (default: None) specifies the color to plot for each vertex; this argument may take a
number of forms:
* None, do not plot a color over the underlay (the default)
* a matrix of RGB or RGBA values, one per vertex
* a property vector or a string naming a property, in which case the cmap, vmin, and vmax
arguments are used to generate colors
* a function that, when passed a single argument, a dict of the properties of a single
vertex, yields an RGB or RGBA list for that vertex.
* cmap (default: 'eccenflat') specifies the colormap to use in plotting if the color
argument provided is a property.
* vmin (default: None) specifies the minimum value for scaling the property when one is passed
as the color option. None means to use the min value of the property.
* vmax (default: None) specifies the maximum value for scaling the property when one is passed
as the color option. None means to use the max value of the property.
* underlay (default: 'curvature') specifies the default underlay color to plot for the
cortical surface; it may be None, 'curvature', or a color.
* alpha (default None) specifies the alpha values to use for the color plot. If None, then
leaves the alpha values from color unchanged. If a single number, then all alpha values in
color are multiplied by that value. If a list of values, one per vertex, then this vector
is multiplied by the alpha values. Finally, any negative value is set instead of multiplied.
So, for example, if there were 3 vertices with:
* color = ((0,0,0,1), (0,0,1,0.5), (0,0,0.75,0,8))
* alpha = (-0.5, 1, 0.5)
then the resulting colors plotted will be ((0,0,0,0.5), (0,0,1,0.5), (0,0,0.75,0,4)).
* mask (default: None) specifies a mask to use for the mesh; thi sis passed through map.mask()
to figure out the masking. Those vertices not in the mask are not plotted (but they will be
plotted in the underlay if it is not None).
* hemi (defaut: None) specifies the hemisphere to use. If the passed mesh object is actually a
subject or mesh pair then this specifies which hemisphere to use. If the passed object is a
mesh, then this overrides its chirality, if specified in meta_data. If two hemispheres are
given, then this may be 'both' or 'split' in accordinace with PySurfer's Brain() class.
* surface (default: 'white') specifies the surface to use if the mesh object passed is in fact
either a cortex or subject object.
* axes (default: None) specifies a particular set of matplotlib pyplot axes that should be
used. If axes is Ellipsis, then instead of attempting to render the plot, a tuple of
(tri, zs, cmap) is returned; in this case, tri is a matplotlib.tri.Triangulation
object for the given map and zs and cmap are an array and colormap (respectively) that
will produce the correct colors. Without axes equal to Ellipsis, these would instead
be rendered as axes.tripcolor(tri, zs, cmap, shading='gouraud'). If axes is None, then
uses the current axes.
* triangulation (default: None) specifies the matplotlib triangulation object to use, if one
already exists; otherwise a new one is made.
'''
if not isinstance(mesh, geo.Mesh) or mesh.coordinates.shape[0] > 2:
# must be a 3D call
return cortex_plot_3D(mesh, *args, **opts)
else:
return cortex_plot_2D(mesh, *args, **opts)