我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用matplotlib.pyplot.figaspect()。
def initialize(self): plt.ion() #Set up plot self.fig = plt.figure(figsize=plt.figaspect(2.)) self.ax0 = self.fig.add_subplot(2,1,1) self.laser_angular, = self.ax0.plot([],[], 'r.') self.laser_filtered, = self.ax0.plot([],[], 'b-') self.ax0.set_ylim(-1, 15) self.ax0.set_xlim(-np.pi, +np.pi) self.ax0.invert_xaxis() self.ax0.grid() self.ax1 = self.fig.add_subplot(2,1,2) self.ax1.invert_xaxis() self.ax1.grid() self.laser_euclid, = self.ax1.plot([],[], '.') self.laser_regressed, = self.ax1.plot([],[], 'g') self.redraw()
def demo(self): # Axes Plots fig = plt.figure(figsize=plt.figaspect(1.)) p = ((0,0), (1,0), (0,1), (1,1)) cb=[0,0,0,1] for i,v in enumerate(self.simple_models.keys()): ax = plt.subplot2grid((2,2), p[i], projection='3d', aspect='equal', ylim=[-1,1], xlim=[-1,1], zlim=[-1,1]) example = SeismicSource(self.simple_models[v]['definition']) example.Aki_Richards.plot(wave='P', style='*', ax=ax, cbarxlabel='P-wave amplitudes', cb=cb[i]) ax.set_title(self.simple_models[v]['name']) plt.tight_layout()
def demodc(self): # Axes Plots fig = plt.figure(figsize=plt.figaspect(2.)) p = ((0,0), (1,0), (2,0)) cb=[0,0,1] for i,v in enumerate(self.simple_models_dc.keys()): ax = plt.subplot2grid((3,1), p[i], projection='3d', aspect='equal', ylim=[-1,1], xlim=[-1,1], zlim=[-1,1]) example = SeismicSource(self.simple_models_dc[v]['definition']) example.Aki_Richards.plot(wave='P', style='*', ax=ax, cbarxlabel='P-wave amplitudes', cb=cb[i]) ax.set_title(self.simple_models_dc[v]['name']) plt.tight_layout()
def lengthDistribution(length_counter,outname): w,h = plt.figaspect(0.4) plt.figure(figsize=(w,h)) x = sorted(length_counter.keys()) y = [length_counter[i] for i in x] plt.bar(x,y,width=0.95,edgecolor="white",align="center",color="#297FFF") plt.savefig(outname + "_readlength_distribution.pdf") plt.close()
def stream_multiplexor_plot(stream,cf): """ Plots the multi-scale time-series resulting from the multiplexors used in `~trigger` for characteristic function calculation (from `~trigger.ShortLongTerms` or `~trigger.leftRightTerms` or `~trigger.Component` classes). ______ :type: - ObsPy:class:`~obspy.core.stream`. - NumPy:class:`~numpy.ndarray` [data-stream, channel, sample]. :param: - data of e.g. seismograms. - multi-scale time-series associated to data, as given by `~trigger.ShortLongTerms.output` or `~trigger.leftRightTerms.output` or `~trigger.Component.output`. _______ :rtype: - matplotlib:class:`~matplotlib.axes.Axes` :return: - axis to use for the plot. ___________ .. rubric:: Example >>> import trigger >>> stlt = trigger.ShortLongTerms(trigger.artificial_stream(npts=500)) >>> trigger.stream_multiplexor_plot(stlt.data, (stlt.output())[0]) """ fig = plt.figure()#figsize=plt.figaspect(1.2)) ax = fig.gca() (tmax,nmax) = streamdatadim(stream) labels = ["" for x in range(tmax)] for t, trace in enumerate(stream): df = trace.stats.sampling_rate npts = trace.stats.npts time = np.arange(npts, dtype=np.float32) / df labels[t] = trace.id ax.plot(time, t+trace.data/(2*np.max(np.abs(trace.data))), '0.5') for c, channel in enumerate(cf[0][t]): if np.sum(cf[1][t][c][0:npts]) != 0 : if len(cf) > 0 : ax.plot(time, t-.5+cf[0][t][c][0:npts]/(np.nanmax(np.abs(cf[0][t][c][0:npts]))), 'r') if len(cf) > 1 : ax.plot(time, t-.5+cf[1][t][c][0:npts]/(np.nanmax(np.abs(cf[1][t][c][0:npts]))), 'b') if len(cf) > 2 : ax.plot(time, t-.5+cf[2][t][c][0:npts]/(np.nanmax(np.abs(cf[1][t][c][0:npts]))), 'g') plt.yticks(np.arange(0, tmax, 1.0)) ax.set_yticklabels(labels) ax.set_xlabel('Time (s)') ax.set_ylabel('Channel') plt.axis('tight') plt.tight_layout() return ax