我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用matplotlib.markers()。
def convert_to_plot(self, plot, coord, offset=True): """ Convert coordinates from projected data coordinates to PlotWindow plot coordinates. Projected data coordinates are two dimensional and refer to the location relative to the specific axes being plotted, although still in simulation units. PlotWindow plot coordinates are locations as found in the final plot, usually with the origin in the center of the image and the extent of the image defined by the final plot axis markers. """ # coord should be a 2 x ncoord array-like datatype. try: ncoord = np.array(coord).shape[1] except IndexError: ncoord = 1 # Convert the data and plot limits to tiled numpy arrays so that # convert_to_plot is automatically vectorized. x0 = np.array(np.tile(plot.xlim[0],ncoord)) x1 = np.array(np.tile(plot.xlim[1],ncoord)) xx0 = np.tile(plot._axes.get_xlim()[0],ncoord) xx1 = np.tile(plot._axes.get_xlim()[1],ncoord) y0 = np.array(np.tile(plot.ylim[0],ncoord)) y1 = np.array(np.tile(plot.ylim[1],ncoord)) yy0 = np.tile(plot._axes.get_ylim()[0],ncoord) yy1 = np.tile(plot._axes.get_ylim()[1],ncoord) ccoord = np.array(coord) # We need a special case for when we are only given one coordinate. if ccoord.shape == (2,): return ((ccoord[0]-x0)/(x1-x0)*(xx1-xx0) + xx0, (ccoord[1]-y0)/(y1-y0)*(yy1-yy0) + yy0) else: return ((ccoord[0][:]-x0)/(x1-x0)*(xx1-xx0) + xx0, (ccoord[1][:]-y0)/(y1-y0)*(yy1-yy0) + yy0)
def random_marker(): markers = mks.MarkerStyle.markers num = len(markers.keys()) idx = random.randint(0, num - 1) return markers.keys()[idx]