Python pylab.fill() Examples
The following are 8
code examples of pylab.fill().
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 also want to check out all available functions/classes of the module
pylab
, or try the search function
.
Example #1
Source File: geoms.py From go2mapillary with GNU General Public License v3.0 | 5 votes |
def fill_polygon(g, o): a = asarray(g.exterior) pylab.fill(a[:,0], a[:,1], o, alpha=0.5)
Example #2
Source File: util.py From face-magnet with Apache License 2.0 | 5 votes |
def drawDef(dfeat, dy, dx, mindef=0.001, distr="father"): """ auxiliary funtion to draw recursive levels of deformation """ from matplotlib.patches import Ellipse pylab.ioff() if distr == "father": py = [0, 0, 2, 2] px = [0, 2, 0, 2] if distr == "child": py = [0, 1, 1, 2] px = [1, 2, 0, 1] ordy = [0, 0, 1, 1] ordx = [0, 1, 0, 1] x1 = -0.5 + dx x2 = 2.5 + dx y1 = -0.5 + dy y2 = 2.5 + dy if distr == "father": pylab.fill([x1, x1, x2, x2, x1], [y1, y2, y2, y1, y1], "r", alpha=0.15, edgecolor="b", lw=1) for l in range(len(py)): aux = dfeat[ordy[l], ordx[l], :].clip(-1, -mindef) wh = numpy.exp(-mindef / aux[0]) / numpy.exp(1) hh = numpy.exp(-mindef / aux[1]) / numpy.exp(1) e = Ellipse( xy=[(px[l] + dx), (py[l] + dy)], width=wh, height=hh, alpha=0.35) x1 = -0.75 + dx + px[l] x2 = 0.75 + dx + px[l] y1 = -0.76 + dy + py[l] y2 = 0.75 + dy + py[l] col = numpy.array([wh * hh] * 3).clip(0, 1) if distr == "father": col[0] = 0 e.set_facecolor(col) pylab.gca().add_artist(e) if distr == "father": pylab.fill([x1, x1, x2, x2, x1], [y1, y2, y2, y1, y1], "b", alpha=0.15, edgecolor="b", lw=1)
Example #3
Source File: plots.py From ColorPy with GNU Lesser General Public License v2.1 | 5 votes |
def rgb_patch_plot ( rgb_colors, color_names, title, filename, patch_gap = 0.05, num_across = 6): '''Draw a set of color patches, specified as linear rgb colors.''' def draw_patch (x0, y0, color, name, patch_gap): '''Draw a patch of color.''' # patch relative vertices m = patch_gap omm = 1.0 - m poly_dx = [m, m, omm, omm] poly_dy = [m, omm, omm, m] # construct vertices poly_x = [ x0 + dx_i for dx_i in poly_dx ] poly_y = [ y0 + dy_i for dy_i in poly_dy ] pylab.fill (poly_x, poly_y, color) if name != None: dtext = 0.1 pylab.text (x0+dtext, y0+dtext, name, size=8.0) # make plot with each color with one patch pylab.clf() num_colors = len (rgb_colors) for i in range (0, num_colors): (iy, ix) = divmod (i, num_across) # get color as a displayable string colorstring = colormodels.irgb_string_from_rgb (rgb_colors [i]) if color_names != None: name = color_names [i] else: name = None draw_patch (float (ix), float (-iy), colorstring, name, patch_gap) pylab.axis ('off') pylab.title (title) print ('Saving plot %s' % str (filename)) pylab.savefig (filename)
Example #4
Source File: plots.py From ColorPy with GNU Lesser General Public License v2.1 | 5 votes |
def spectrum_subplot (spectrum): '''Plot a spectrum, with x-axis the wavelength, and y-axis the intensity. The curve is colored at that wavelength by the (approximate) color of a pure spectral color at that wavelength, with intensity constant over wavelength. (This means that dark looking colors here mean that wavelength is poorly viewed by the eye. This is not a complete plotting function, e.g. no file is saved, etc. It is assumed that this function is being called by one that handles those things.''' (num_wl, num_cols) = spectrum.shape # get rgb colors for each wavelength rgb_colors = numpy.empty ((num_wl, 3)) for i in range (0, num_wl): wl_nm = spectrum [i][0] xyz = ciexyz.xyz_from_wavelength (wl_nm) rgb_colors [i] = colormodels.rgb_from_xyz (xyz) # scale to make brightest rgb value = 1.0 rgb_max = numpy.max (rgb_colors) scaling = 1.0 / rgb_max rgb_colors *= scaling # draw color patches (thin vertical lines matching the spectrum curve) in color for i in range (0, num_wl-1): # skipping the last one here to stay in range x0 = spectrum [i][0] x1 = spectrum [i+1][0] y0 = spectrum [i][1] y1 = spectrum [i+1][1] poly_x = [x0, x1, x1, x0] poly_y = [0.0, 0.0, y1, y0] color_string = colormodels.irgb_string_from_rgb (rgb_colors [i]) pylab.fill (poly_x, poly_y, color_string, edgecolor=color_string) # plot intensity as a curve pylab.plot ( spectrum [:,0], spectrum [:,1], color='k', linewidth=2.0, antialiased=True)
Example #5
Source File: util.py From face-magnet with Apache License 2.0 | 4 votes |
def drawDeform(dfeat, mindef=0.001): """ draw the deformation weight of an object model """ from matplotlib.patches import Ellipse lev = len(dfeat) if 1: sy = 1 sx = lev else: sy = lev sx = 1 pylab.subplot(sy, sx, 1) x1 = -0.5 x2 = 0.5 y1 = -0.5 y2 = 0.5 pylab.fill([x1, x1, x2, x2, x1], [y1, y2, y2, y1, y1], "b", alpha=0.15, edgecolor="b", lw=1) pylab.fill([x1, x1, x2, x2, x1], [y1, y2, y2, y1, y1], "r", alpha=0.15, edgecolor="r", lw=1) wh = numpy.exp(-mindef / dfeat[0][0, 0, 0]) / numpy.exp(1) hh = numpy.exp(-mindef / dfeat[0][0, 0, 1]) / numpy.exp(1) e = Ellipse(xy=[0, 0], width=wh, height=hh, alpha=0.35) col = numpy.array([wh * hh] * 3).clip(0, 1) col[0] = 0 e.set_facecolor(col) pylab.axis("off") pylab.gca().add_artist(e) pylab.gca().set_ylim(-0.5, 0.5) pylab.gca().set_xlim(-0.5, 0.5) for l in range(1, lev): pylab.subplot(sy, sx, l + 1) for ry in range(2 ** (l - 1)): for rx in range(2 ** (l - 1)): drawDef(dfeat[l][ry * 2:(ry + 1) * 2, rx * 2:(rx + 1) * 2, 2:] * 4 ** l, 4 * ry, 4 * rx, distr="child") drawDef(dfeat[l][ry * 2:(ry + 1) * 2, rx * 2:(rx + 1) * 2, :2] * 4 ** l, ry * 2 ** (l), rx * 2 ** (l), mindef=mindef, distr="father") # pylab.gca().set_ylim(-0.5,(2.6)**l) pylab.axis("off") pylab.gca().set_ylim((2.6) ** l, -0.5) pylab.gca().set_xlim(-0.5, (2.6) ** l)
Example #6
Source File: plots.py From ColorPy with GNU Lesser General Public License v2.1 | 4 votes |
def spectrum_plot ( spectrum, title, filename, xlabel = 'Wavelength ($nm$)', ylabel = 'Intensity ($W/m^2$)'): '''Plot for a single spectrum - In a two part graph, plot: top: color of the spectrum, as a large patch. low: graph of spectrum intensity vs wavelength (x axis). The graph is colored by the (approximated) color of each wavelength. Each wavelength has equal physical intensity, so the variation in apparent intensity (e.g. 400, 800 nm are very dark, 550 nm is bright), is due to perceptual factors in the eye. This helps show how much each wavelength contributes to the percieved color. spectrum - spectrum to plot title - title for plot filename - filename to save plot to xlabel - label for x axis ylabel - label for y axis ''' pylab.clf () # upper plot - solid patch of color that matches the spectrum color pylab.subplot (2,1,1) pylab.title (title) color_string = colormodels.irgb_string_from_rgb ( colormodels.rgb_from_xyz (ciexyz.xyz_from_spectrum (spectrum))) poly_x = [0.0, 1.0, 1.0, 0.0] poly_y = [0.0, 0.0, 1.0, 1.0] pylab.fill (poly_x, poly_y, color_string) # draw a solid line around the patch to look nicer pylab.plot (poly_x, poly_y, color='k', linewidth=2.0) pylab.axis ('off') # lower plot - spectrum vs wavelength, with colors of the associated spectral lines below pylab.subplot (2,1,2) spectrum_subplot (spectrum) tighten_x_axis (spectrum [:,0]) pylab.xlabel (xlabel) pylab.ylabel (ylabel) # done print ('Saving plot %s' % str (filename)) pylab.savefig (filename) # # Color vs param plot #
Example #7
Source File: plots.py From ColorPy with GNU Lesser General Public License v2.1 | 4 votes |
def color_vs_param_plot ( param_list, rgb_colors, title, filename, tight = False, plotfunc = pylab.plot, xlabel = 'param', ylabel = 'RGB Color'): '''Plot for a color that varies with a parameter - In a two part figure, draw: top: color as it varies with parameter (x axis) low: r,g,b values, as linear 0.0-1.0 values, of the attempted color. param_list - list of parameters (x axis) rgb_colors - numpy array, one row for each param in param_list title - title for plot filename - filename to save plot to plotfunc - optional plot function to use (default pylab.plot) xlabel - label for x axis ylabel - label for y axis (default 'RGB Color') ''' pylab.clf () # draw color bars in upper plot pylab.subplot (2,1,1) pylab.title (title) # no xlabel, ylabel in upper plot num_points = len (param_list) for i in range (0, num_points-1): x0 = param_list [i] x1 = param_list [i+1] y0 = 0.0 y1 = 1.0 poly_x = [x0, x1, x1, x0] poly_y = [y0, y0, y1, y1] color_string = colormodels.irgb_string_from_rgb (rgb_colors [i]) pylab.fill (poly_x, poly_y, color_string, edgecolor=color_string) if tight: tighten_x_axis (param_list) # draw rgb curves in lower plot pylab.subplot (2,1,2) # no title in lower plot plotfunc (param_list, rgb_colors [:,0], color='r', label='Red') plotfunc (param_list, rgb_colors [:,1], color='g', label='Green') plotfunc (param_list, rgb_colors [:,2], color='b', label='Blue') if tight: tighten_x_axis (param_list) pylab.xlabel (xlabel) pylab.ylabel (ylabel) print ('Saving plot %s' % str (filename)) pylab.savefig (filename) # # Some specialized plots #
Example #8
Source File: dataset_float.py From DEMUD with Apache License 2.0 | 4 votes |
def plot_item_triangles(self, m, ind, x, r, k, label, U, rerr, feature_weights, band_ind): """plot_item_triangles(self, m, ind, x, r, k, label, U, rerr, feature_weights, band_ind) Plot selection m (index ind, data in x) with triangles to mark the largest residual values on band_ind indices (i.e., you need to pick them before calling this). To use this, define plot_item() in your data set's class to call this function instead. """ if x == [] or r == []: print "Error: No data in x and/or r." return pylab.clf() # xvals, x, and r need to be column vectors pylab.plot(self.xvals, r, 'r-', linewidth=0.5, label='Expected') pylab.plot(self.xvals, x, 'b.-', linewidth=1, label='Observations') # Boost font sizes for axis and tick labels pylab.xlabel(self.xlabel) #, fontsize=16) pylab.ylabel(self.ylabel) #, fontsize=16) ''' pylab.xticks(fontsize=16) pylab.yticks(fontsize=16) ''' pylab.title('DEMUD selection %d (%s), item %d, using K=%d' % \ (m, label, ind, k)) pylab.legend(fontsize=10) # width of triangles to plot width = (self.xvals.max() - self.xvals.min())/100.0 for band in band_ind: w = float(self.xvals[band]) reproj = r[band] # Draw a triangle that points up if r > x # or down if r < x pylab.fill([w-width, w+width, w], [reproj, reproj, x[band]], '0.6', zorder=1) outdir = os.path.join('results', self.name) if not os.path.exists(outdir): os.mkdir(outdir) figfile = os.path.join(outdir, 'sel-%d-k-%d-(%s).pdf' % (m, k, label)) pylab.savefig(figfile) print 'Wrote plot to %s' % figfile pylab.close()