Python matplotlib.pyplot.autoscale() Examples
The following are 30
code examples of matplotlib.pyplot.autoscale().
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
matplotlib.pyplot
, or try the search function
.
Example #1
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_use_sticky_edges(): fig, ax = plt.subplots() ax.imshow([[0, 1], [2, 3]], origin='lower') assert_allclose(ax.get_xlim(), (-0.5, 1.5)) assert_allclose(ax.get_ylim(), (-0.5, 1.5)) ax.use_sticky_edges = False ax.autoscale() xlim = (-0.5 - 2 * ax._xmargin, 1.5 + 2 * ax._xmargin) ylim = (-0.5 - 2 * ax._ymargin, 1.5 + 2 * ax._ymargin) assert_allclose(ax.get_xlim(), xlim) assert_allclose(ax.get_ylim(), ylim) # Make sure it is reversible: ax.use_sticky_edges = True ax.autoscale() assert_allclose(ax.get_xlim(), (-0.5, 1.5)) assert_allclose(ax.get_ylim(), (-0.5, 1.5))
Example #2
Source File: log_analyzer.py From pylinac with MIT License | 6 votes |
def plot_subimage(self, img, ax=None, show=True, fontsize=10): # img: {'actual', 'expected', 'gamma'} if ax is None: ax = plt.subplot() ax.tick_params(axis='both', labelsize=8) if img in ('actual', 'expected'): title = img.capitalize() + ' Fluence' plt.imshow(getattr(self.fluence, img).array.astype(np.float32), aspect='auto', interpolation='none', cmap=get_array_cmap()) elif img == 'gamma': plt.imshow(getattr(self.fluence, img).array.astype(np.float32), aspect='auto', interpolation='none', vmax=1, cmap=get_array_cmap()) plt.colorbar(ax=ax) title = 'Gamma Map' ax.autoscale(tight=True) ax.set_title(title, fontsize=fontsize) if show: plt.show()
Example #3
Source File: ct.py From pylinac with MIT License | 6 votes |
def plot_profiles(self, axis=None): """Plot the horizontal and vertical profiles of the Uniformity slice. Parameters ---------- axis : None, matplotlib.Axes The axis to plot on; if None, will create a new figure. """ if axis is None: fig, axis = plt.subplots() horiz_data = self.image[int(self.phan_center.y), :] vert_data = self.image[:, int(self.phan_center.x)] axis.plot(horiz_data, 'g', label='Horizontal') axis.plot(vert_data, 'b', label='Vertical') axis.autoscale(tight=True) axis.axhline(self.tolerance, color='r', linewidth=3) axis.axhline(-self.tolerance, color='r', linewidth=3) axis.grid(True) axis.set_ylabel("HU") axis.legend(loc=8, fontsize='small', title="") axis.set_title("Uniformity Profiles")
Example #4
Source File: analysis.py From px4tools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def pos_analysis(data): """ Analyze position. """ tmerc_map = mapping.create_map(data.GPS_Lon.values, data.GPS_Lat.values) gps_y, gps_x = tmerc_map(data.GPS_Lon.values, data.GPS_Lat.values) gpos_y, gpos_x = tmerc_map(data.GPOS_Lon.values, data.GPOS_Lat.values) gpsp_y, gpsp_x = tmerc_map( data.GPSP_Lon[np.isfinite(data.GPSP_Lon.values)].values, data.GPSP_Lat[np.isfinite(data.GPSP_Lat.values)].values) import matplotlib.pyplot as plt plt.plot(gpos_y, gpos_x, '.', label='est') plt.plot(gps_y, gps_x, 'x', label='GPS') plt.plot(gpsp_y, gpsp_x, 'ro', label='cmd') plt.xlabel('E, m') plt.ylabel('N, m') plt.grid() plt.autoscale(True, 'both', True) plt.legend(loc='best') return locals()
Example #5
Source File: test_axes.py From coffeegrindsize with MIT License | 6 votes |
def test_use_sticky_edges(): fig, ax = plt.subplots() ax.imshow([[0, 1], [2, 3]], origin='lower') assert_allclose(ax.get_xlim(), (-0.5, 1.5)) assert_allclose(ax.get_ylim(), (-0.5, 1.5)) ax.use_sticky_edges = False ax.autoscale() xlim = (-0.5 - 2 * ax._xmargin, 1.5 + 2 * ax._xmargin) ylim = (-0.5 - 2 * ax._ymargin, 1.5 + 2 * ax._ymargin) assert_allclose(ax.get_xlim(), xlim) assert_allclose(ax.get_ylim(), ylim) # Make sure it is reversible: ax.use_sticky_edges = True ax.autoscale() assert_allclose(ax.get_xlim(), (-0.5, 1.5)) assert_allclose(ax.get_ylim(), (-0.5, 1.5))
Example #6
Source File: utils.py From generative-graph-transformer with MIT License | 6 votes |
def full_frame_high_res(plt, width=3.2, height=3.2): r""" Generates a particular tight layout for Pyplot plots, at higher resolution :param plt: pyplot :param width: width, default is 320 pixels :param height: height, default is 320 pixels :return: """ import matplotlib as mpl mpl.rcParams['savefig.pad_inches'] = 0 figsize = None if width is None else (width, height) fig = plt.figure(figsize=figsize) ax = plt.axes([0, 0, 1, 1], frameon=False) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) plt.autoscale(tight=True)
Example #7
Source File: utils.py From generative-graph-transformer with MIT License | 6 votes |
def full_frame(plt, width=0.64, height=0.64): r""" Generates a particular tight layout for Pyplot plots :param plt: pyplot :param width: width, default is 64 pixels :param height: height, default is 64 pixels :return: """ import matplotlib as mpl mpl.rcParams['savefig.pad_inches'] = 0 figsize = None if width is None else (width, height) fig = plt.figure(figsize=figsize) ax = plt.axes([0, 0, 1, 1], frameon=False) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) plt.autoscale(tight=True)
Example #8
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_use_sticky_edges(): fig, ax = plt.subplots() ax.imshow([[0, 1], [2, 3]], origin='lower') assert_allclose(ax.get_xlim(), (-0.5, 1.5)) assert_allclose(ax.get_ylim(), (-0.5, 1.5)) ax.use_sticky_edges = False ax.autoscale() xlim = (-0.5 - 2 * ax._xmargin, 1.5 + 2 * ax._xmargin) ylim = (-0.5 - 2 * ax._ymargin, 1.5 + 2 * ax._ymargin) assert_allclose(ax.get_xlim(), xlim) assert_allclose(ax.get_ylim(), ylim) # Make sure it is reversible: ax.use_sticky_edges = True ax.autoscale() assert_allclose(ax.get_xlim(), (-0.5, 1.5)) assert_allclose(ax.get_ylim(), (-0.5, 1.5))
Example #9
Source File: SquigglePlot.py From SquiggleKit with MIT License | 5 votes |
def view_sig(args, sig, name, path=None): ''' View the squiggle ''' fig = plt.figure(1) # fig.subplots_adjust(hspace=0.1, wspace=0.01) # ax = fig.add_subplot(111) # plt.tight_layout() plt.autoscale() plt.title("Raw signal for: {}".format(name)) plt.xlabel("") # print(sig.dtype) # print(sig.dtype == float64) if sig.dtype == float: plt.ylabel("Current (pA)") elif sig.dtype == int: plt.ylabel("Current - Not scaled") plt.plot(sig, color=args.plot_colour) if args.save: filename = os.path.join(args.save_path, "{}_dpi_{}_{}".format(name, args.dpi, args.save)) plt.savefig(filename) if not args.no_show: plt.show() plt.clf()
Example #10
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_autoscale_tight(): fig, ax = plt.subplots(1, 1) ax.plot([1, 2, 3, 4]) ax.autoscale(enable=True, axis='x', tight=False) ax.autoscale(enable=True, axis='y', tight=True) assert_allclose(ax.get_xlim(), (-0.15, 3.15)) assert_allclose(ax.get_ylim(), (1.0, 4.0))
Example #11
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_autoscale_log_shared(): # related to github #7587 # array starts at zero to trigger _minpos handling x = np.arange(100, dtype=float) fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True) ax1.loglog(x, x) ax2.semilogx(x, x) ax1.autoscale(tight=True) ax2.autoscale(tight=True) plt.draw() lims = (x[1], x[-1]) assert_allclose(ax1.get_xlim(), lims) assert_allclose(ax1.get_ylim(), lims) assert_allclose(ax2.get_xlim(), lims) assert_allclose(ax2.get_ylim(), (x[0], x[-1]))
Example #12
Source File: test_axes.py From coffeegrindsize with MIT License | 5 votes |
def test_autoscale_tight(): fig, ax = plt.subplots(1, 1) ax.plot([1, 2, 3, 4]) ax.autoscale(enable=True, axis='x', tight=False) ax.autoscale(enable=True, axis='y', tight=True) assert_allclose(ax.get_xlim(), (-0.15, 3.15)) assert_allclose(ax.get_ylim(), (1.0, 4.0))
Example #13
Source File: ct.py From pylinac with MIT License | 5 votes |
def plot_analyzed_image(self, show=True): """Plot the images used in the calculate and summary data. Parameters ---------- show : bool Whether to plot the image or not. """ def plot(ctp_module, axis): axis.imshow(ctp_module.image.array, cmap=get_dicom_cmap()) ctp_module.plot_rois(axis) axis.autoscale(tight=True) axis.set_title(ctp_module.common_name) axis.axis('off') # set up grid and axes grid_size = (2, 4) hu_ax = plt.subplot2grid(grid_size, (0, 1)) plot(self.ctp404, hu_ax) hu_lin_ax = plt.subplot2grid(grid_size, (0, 2)) self.ctp404.plot_linearity(hu_lin_ax) if self._has_module(CTP486): unif_ax = plt.subplot2grid(grid_size, (0, 0)) plot(self.ctp486, unif_ax) unif_prof_ax = plt.subplot2grid(grid_size, (1, 2), colspan=2) self.ctp486.plot_profiles(unif_prof_ax) if self._has_module(CTP528CP504): sr_ax = plt.subplot2grid(grid_size, (1, 0)) plot(self.ctp528, sr_ax) mtf_ax = plt.subplot2grid(grid_size, (0, 3)) self.ctp528.plot_mtf(mtf_ax) if self._has_module(CTP515): locon_ax = plt.subplot2grid(grid_size, (1, 1)) plot(self.ctp515, locon_ax) # finish up plt.tight_layout() if show: plt.show()
Example #14
Source File: test_axes.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_autoscale_log_shared(): # related to github #7587 # array starts at zero to trigger _minpos handling x = np.arange(100, dtype=float) fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True) ax1.loglog(x, x) ax2.semilogx(x, x) ax1.autoscale(tight=True) ax2.autoscale(tight=True) plt.draw() lims = (x[1], x[-1]) assert_allclose(ax1.get_xlim(), lims) assert_allclose(ax1.get_ylim(), lims) assert_allclose(ax2.get_xlim(), lims) assert_allclose(ax2.get_ylim(), (x[0], x[-1]))
Example #15
Source File: sockets.py From sarviewer with GNU General Public License v3.0 | 5 votes |
def generate_graph(): with open('../../data/sockets.dat', 'r') as csvfile: data_source = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) for row in data_source: # [0] column is a time column # Convert to datetime data type a = datetime.strptime((row[0]),'%H:%M:%S') x.append((a)) # The remaining columns contain data t_tcp.append(str((int(row[2]))+(int(row[6])))) t_tcp_use.append(row[2]) t_udp_use.append(row[3]) t_tcp_time_wait.append(row[6]) # Plot lines plt.plot(x,t_tcp, label='Total TCP sockets', color='#ff9933', antialiased=True) plt.plot(x,t_tcp_use, label='TCP sockets in use', color='#66ccff', antialiased=True) plt.plot(x,t_udp_use, label='UDP sockets in use', color='#009933', antialiased=True) plt.plot(x,t_tcp_time_wait, label='TCP sockets in TIME WAIT state', color='#cc3300', antialiased=True) # Graph properties plt.xlabel('Time',fontstyle='italic') plt.ylabel('Number of sockets',fontstyle='italic') plt.title('Sockets') plt.grid(linewidth=0.4, antialiased=True) plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.20), ncol=2, fancybox=True, shadow=True) plt.autoscale(True) # Graph saved to PNG file plt.savefig('../../graphs/sockets.png', bbox_inches='tight') #plt.show() # ====================== # MAIN # ======================
Example #16
Source File: log_analyzer.py From pylinac with MIT License | 5 votes |
def _plot(self, param='', show=True): """Plot the parameter: actual, expected, or difference.""" plt.plot(getattr(self, param)) plt.grid(True) plt.autoscale(axis='x', tight=True) if show: plt.show()
Example #17
Source File: nanotron.py From picasso with MIT License | 5 votes |
def show_probs(self): if self.predicting is False: if not hasattr(self.locs, "score"): msgBox = QtWidgets.QMessageBox(self) msgBox.setIcon(QtWidgets.QMessageBox.Information) msgBox.setWindowTitle("Information") msgBox.setText("No predictions found") msgBox.setInformativeText("Predict first and try again.") msgBox.exec_() else: canvas = GenericPlotWindow("Probabilities") canvas.figure.clear() probabilities_per_pick = np.zeros(len(np.unique(self.locs.group))) for c, group_number in enumerate(np.unique(self.locs.group)): pick = self.locs[self.locs.group == group_number] pick_score = np.unique(pick.score)[0] probabilities_per_pick[c] = pick_score ax1 = canvas.figure.subplots(1, 1) ax1.hist(probabilities_per_pick, bins=100, range=(0,1.0), align="mid", rwidth = 1) ax1.set_xlabel("Probability") ax1.set_ylabel("Counts") plt.autoscale() plt.tight_layout() canvas.canvas.draw() canvas.show()
Example #18
Source File: nanotron.py From picasso with MIT License | 5 votes |
def show_learning_stats(self): if self.mlp is not None: canvas = GenericPlotWindow("Learning history") canvas.figure.clear() ax1, ax2 = canvas.figure.subplots(1, 2) ax1.set_title("Learning Curve") ax1.plot(self.mlp.loss_curve_, label="Train") ax1.legend(loc="best") ax1.set_xlabel("Iterations") ax1.set_ylabel("Loss") im = ax2.imshow(self.cm, interpolation="nearest", cmap=plt.cm.Blues) ax2.figure.colorbar(im, ax=ax2) ax2.set(xticks=np.arange(self.cm.shape[1]), yticks=np.arange(self.cm.shape[0]), xticklabels=self.classes.values(), yticklabels=self.classes.values(), title="Confusion Matrix", ylabel="True label", xlabel="Predicted label") plt.setp(ax2.get_yticklabels(), rotation="vertical", horizontalalignment="right", verticalalignment="center") thresh = self.cm.max() / 2. for i in range(self.cm.shape[0]): for j in range(self.cm.shape[1]): ax2.text(j, i, format(self.cm[i, j], "d"), ha="center", va="center", color="white" if self.cm[i, j] > thresh else "black") plt.autoscale() plt.tight_layout() canvas.canvas.draw() canvas.show()
Example #19
Source File: cpu.py From sarviewer with GNU General Public License v3.0 | 5 votes |
def generate_graph(): with open('../../data/cpu.dat', 'r') as csvfile: data_source = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) for row in data_source: # [0] column is a time column # Convert to datetime data type a = datetime.strptime((row[0]),'%H:%M:%S') x.append((a)) # The remaining columns contain data user_cpu.append(row[2]) system_cpu.append(row[4]) idle_cpu.append(row[7]) # Plot lines plt.plot(x,user_cpu, label='User %', color='g', antialiased=True) plt.plot(x,system_cpu, label='System %', color='r', antialiased=True) plt.plot(x,idle_cpu, label='Idle %', color='b', antialiased=True) # Graph properties plt.xlabel('Time',fontstyle='italic') plt.ylabel('CPU %',fontstyle='italic') plt.title('CPU usage graph') plt.grid(linewidth=0.4, antialiased=True) plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=2, fancybox=True, shadow=True) plt.autoscale(True) # Graph saved to PNG file plt.savefig('../../graphs/cpu.png', bbox_inches='tight') #plt.show() # ====================== # MAIN # ======================
Example #20
Source File: iotransfer.py From sarviewer with GNU General Public License v3.0 | 5 votes |
def generate_graph(): with open('../../data/iotransfer.dat', 'r') as csvfile: data_source = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) for row in data_source: # [0] column is a time column # Convert to datetime data type a = datetime.strptime((row[0]),'%H:%M:%S') x.append((a)) # The remaining columns contain data b_read_second.append(row[4]) b_written_second.append(row[5]) # Plot lines plt.plot(x,b_read_second, label='Blocks read per second', color='r', antialiased=True) plt.plot(x,b_written_second, label='Blocks written per second', color='g', antialiased=True) # Graph properties plt.xlabel('Time',fontstyle='italic') plt.ylabel('Blocks per second',fontstyle='italic') plt.title('IO Transfer graph') plt.grid(linewidth=0.4, antialiased=True) plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=2, fancybox=True, shadow=True) plt.autoscale(True) # Graph saved to PNG file plt.savefig('../../graphs/iotransfer.png', bbox_inches='tight') #plt.show() # ====================== # MAIN # ======================
Example #21
Source File: analyze_webstats.py From Building-Machine-Learning-Systems-With-Python-Second-Edition with MIT License | 5 votes |
def plot_models(x, y, models, fname, mx=None, ymax=None, xmin=None): plt.figure(num=None, figsize=(8, 6)) plt.clf() plt.scatter(x, y, s=10) plt.title("Web traffic over the last month") plt.xlabel("Time") plt.ylabel("Hits/hour") plt.xticks( [w * 7 * 24 for w in range(10)], ['week %i' % w for w in range(10)]) if models: if mx is None: mx = sp.linspace(0, x[-1], 1000) for model, style, color in zip(models, linestyles, colors): # print "Model:",model # print "Coeffs:",model.coeffs plt.plot(mx, model(mx), linestyle=style, linewidth=2, c=color) plt.legend(["d=%i" % m.order for m in models], loc="upper left") plt.autoscale(tight=True) plt.ylim(ymin=0) if ymax: plt.ylim(ymax=ymax) if xmin: plt.xlim(xmin=xmin) plt.grid(True, linestyle='-', color='0.75') plt.savefig(fname) # first look at the data
Example #22
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_autoscale_tight(): fig, ax = plt.subplots(1, 1) ax.plot([1, 2, 3, 4]) ax.autoscale(enable=True, axis='x', tight=False) ax.autoscale(enable=True, axis='y', tight=True) assert_allclose(ax.get_xlim(), (-0.15, 3.15)) assert_allclose(ax.get_ylim(), (1.0, 4.0))
Example #23
Source File: netinterface.py From sarviewer with GNU General Public License v3.0 | 5 votes |
def generate_graph(): with open('../../data/netinterface.dat', 'r') as csvfile: data_source = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) for row in data_source: # [0] column is a time column # Convert to datetime data type a = datetime.strptime((row[0]),'%H:%M:%S') x.append((a)) # The remaining columns contain data r_kb.append(row[4]) s_kb.append(row[5]) # Plot lines plt.plot(x,r_kb, label='Kilobytes received per second', color='#009973', antialiased=True) plt.plot(x,s_kb, label='Kilobytes sent per second', color='#b3b300', antialiased=True) # Graph properties plt.xlabel('Time',fontstyle='italic') plt.ylabel('Kb/s',fontstyle='italic') plt.title('Network statistics') plt.grid(linewidth=0.4, antialiased=True) plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.18), ncol=2, fancybox=True, shadow=True) plt.autoscale(True) # Graph saved to PNG file plt.savefig('../../graphs/netinterface.png', bbox_inches='tight') #plt.show() # ====================== # MAIN # ======================
Example #24
Source File: tasks.py From sarviewer with GNU General Public License v3.0 | 5 votes |
def generate_graph(): with open('../../data/loadaverage.dat', 'r') as csvfile: data_source = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) for row in data_source: # [0] column is a time column # Convert to datetime data type a = datetime.strptime((row[0]),'%H:%M:%S') x.append((a)) # The remaining columns contain data t_run_queue.append(row[1]) t_total.append(row[2]) t_blocked.append(row[6]) # Plot lines plt.plot(x,t_run_queue, label='Tasks in run queue', color='g', antialiased=True) plt.plot(x,t_total, label='Total active tasks (processes + threads)', color='r', antialiased=True) plt.plot(x,t_blocked, label='Blocked tasks', color='m', antialiased=True) # Graph properties plt.xlabel('Time',fontstyle='italic') plt.ylabel('Tasks',fontstyle='italic') plt.title('Tasks graph') plt.grid(linewidth=0.4, antialiased=True) plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=2, fancybox=True, shadow=True) plt.autoscale(True) # Graph saved to PNG file plt.savefig('../../graphs/tasks.png', bbox_inches='tight') #plt.show() # ====================== # MAIN # ======================
Example #25
Source File: proc.py From sarviewer with GNU General Public License v3.0 | 5 votes |
def generate_graph(): with open('../../data/proc.dat', 'r') as csvfile: data_source = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) for row in data_source: # [0] column is a time column # Convert to datetime data type a = datetime.strptime((row[0]),'%H:%M:%S') x.append((a)) # The remaining columns contain data procs_per_second.append(row[1]) # Plot lines plt.plot(x,procs_per_second, label='Processes created per second', color='r', antialiased=True) # Graph properties plt.xlabel('Time',fontstyle='italic') plt.ylabel('Processes',fontstyle='italic') plt.title('Processes created per second graph') plt.grid(linewidth=0.4, antialiased=True) plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=2, fancybox=True, shadow=True) plt.autoscale(True) # Graph saved to PNG file plt.savefig('../../graphs/proc.png', bbox_inches='tight') #plt.show() # ====================== # MAIN # ======================
Example #26
Source File: swap.py From sarviewer with GNU General Public License v3.0 | 5 votes |
def generate_graph(): with open('../../data/swap.dat', 'r') as csvfile: data_source = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) for row in data_source: # [0] column is a time column # Convert to datetime data type a = datetime.strptime((row[0]),'%H:%M:%S') x.append((a)) # The remaining columns contain data swap_free.append(str(int(row[1])/1024)) swap_used.append(str(int(row[2])/1024)) # Plot lines plt.plot(x,swap_used, label='Used', color='r', antialiased=True) plt.plot(x,swap_free, label='Free', color='g', antialiased=True) # Graph properties plt.xlabel('Time',fontstyle='italic') plt.ylabel('SWAP (MB)',fontstyle='italic') plt.title('SWAP usage graph') plt.grid(linewidth=0.4, antialiased=True) plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=2, fancybox=True, shadow=True) plt.autoscale(True) # Graph saved to PNG file plt.savefig('../../graphs/swap.png', bbox_inches='tight') #plt.show() # ====================== # MAIN # ======================
Example #27
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_autoscale_log_shared(): # related to github #7587 # array starts at zero to trigger _minpos handling x = np.arange(100, dtype=float) fig, (ax1, ax2) = plt.subplots(2, 1, sharex=True) ax1.loglog(x, x) ax2.semilogx(x, x) ax1.autoscale(tight=True) ax2.autoscale(tight=True) plt.draw() lims = (x[1], x[-1]) assert_allclose(ax1.get_xlim(), lims) assert_allclose(ax1.get_ylim(), lims) assert_allclose(ax2.get_xlim(), lims) assert_allclose(ax2.get_ylim(), (x[0], x[-1]))
Example #28
Source File: ram.py From sarviewer with GNU General Public License v3.0 | 5 votes |
def generate_graph(): with open('../../data/ram.dat', 'r') as csvfile: data_source = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) for row in data_source: # [0] column is a time column # Convert to datetime data type a = datetime.strptime((row[0]),'%H:%M:%S') x.append((a)) # The remaining columns contain data free_mem.append(str((int(row[1])/1024)+(int(row[4])/1024)+(int(row[5])/1024))) used_mem.append(str((int(row[2])/1024)-(int(row[4])/1024)-(int(row[5])/1024))) buffer_mem.append(str(int(row[4])/1024)) cached_mem.append(str(int(row[5])/1024)) # Plot lines plt.plot(x,free_mem, label='Free', color='g', antialiased=True) plt.plot(x,used_mem, label='Used', color='r', antialiased=True) plt.plot(x,buffer_mem, label='Buffer', color='b', antialiased=True) plt.plot(x,cached_mem, label='Cached', color='c', antialiased=True) # Graph properties plt.xlabel('Time',fontstyle='italic') plt.ylabel('Memory (MB)',fontstyle='italic') plt.title('RAM usage graph') plt.grid(linewidth=0.4, antialiased=True) plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=2, fancybox=True, shadow=True) plt.autoscale(True) # Graph saved to PNG file plt.savefig('../../graphs/ram.png', bbox_inches='tight') #plt.show() # ====================== # MAIN # ======================
Example #29
Source File: loadaverage.py From sarviewer with GNU General Public License v3.0 | 5 votes |
def generate_graph(): with open('../../data/loadaverage.dat', 'r') as csvfile: data_source = csv.reader(csvfile, delimiter=' ', skipinitialspace=True) for row in data_source: # [0] column is a time column # Convert to datetime data type a = datetime.strptime((row[0]),'%H:%M:%S') x.append((a)) # The remaining columns contain data m1.append(row[3]) m5.append(row[4]) m15.append(row[5]) # Plot lines plt.plot(x,m1, label='1 min', color='g', antialiased=True) plt.plot(x,m5, label='5 min', color='r', antialiased=True) plt.plot(x,m15, label='15 min', color='b', antialiased=True) # Graph properties plt.xlabel('Time',fontstyle='italic') plt.ylabel('Load average',fontstyle='italic') plt.title('Load average graph') plt.grid(linewidth=0.4, antialiased=True) plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=2, fancybox=True, shadow=True) plt.autoscale(True) # Graph saved to PNG file plt.savefig('../../graphs/loadaverage.png', bbox_inches='tight') #plt.show() # ====================== # MAIN # ======================
Example #30
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_inverted_cla(): # Github PR #5450. Setting autoscale should reset # axes to be non-inverted. # plotting an image, then 1d graph, axis is now down fig = plt.figure(0) ax = fig.gca() # 1. test that a new axis is not inverted per default assert not ax.xaxis_inverted() assert not ax.yaxis_inverted() img = np.random.random((100, 100)) ax.imshow(img) # 2. test that a image axis is inverted assert not ax.xaxis_inverted() assert ax.yaxis_inverted() # 3. test that clearing and plotting a line, axes are # not inverted ax.cla() x = np.linspace(0, 2*np.pi, 100) ax.plot(x, np.cos(x)) assert not ax.xaxis_inverted() assert not ax.yaxis_inverted() # 4. autoscaling should not bring back axes to normal ax.cla() ax.imshow(img) plt.autoscale() assert not(ax.xaxis_inverted()) assert ax.yaxis_inverted() # 5. two shared axes. Clearing the master axis should bring axes in shared # axes back to normal ax0 = plt.subplot(211) ax1 = plt.subplot(212, sharey=ax0) ax0.imshow(img) ax1.plot(x, np.cos(x)) ax0.cla() assert not(ax1.yaxis_inverted()) ax1.cla() # 6. clearing the nonmaster should not touch limits ax0.imshow(img) ax1.plot(x, np.cos(x)) ax1.cla() assert ax.yaxis_inverted() # clean up plt.close(fig)