Python matplotlib.Figure() Examples
The following are 7
code examples of matplotlib.Figure().
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
, or try the search function
.
Example #1
Source File: exporter.py From mplexporter with BSD 3-Clause "New" or "Revised" License | 6 votes |
def run(self, fig): """ Run the exporter on the given figure Parmeters --------- fig : matplotlib.Figure instance The figure to export """ # Calling savefig executes the draw() command, putting elements # in the correct place. if fig.canvas is None: canvas = FigureCanvasAgg(fig) fig.savefig(io.BytesIO(), format='png', dpi=fig.dpi) if self.close_mpl: import matplotlib.pyplot as plt plt.close(fig) self.crawl_fig(fig)
Example #2
Source File: exporter.py From lddmm-ot with MIT License | 6 votes |
def run(self, fig): """ Run the exporter on the given figure Parmeters --------- fig : matplotlib.Figure instance The figure to export """ # Calling savefig executes the draw() command, putting elements # in the correct place. fig.savefig(io.BytesIO(), format='png', dpi=fig.dpi) if self.close_mpl: import matplotlib.pyplot as plt plt.close(fig) self.crawl_fig(fig)
Example #3
Source File: visualization.py From chemml with BSD 3-Clause "New" or "Revised" License | 5 votes |
def fit(self, figure): """ the main function to fit the parameters to the input figure Parameters ---------- figure: matplotlib.figure.Figure object or matplotlib.AxesSubplot object this function only proceed with one set of axes in the figure. Returns ------- matplotlib.figure.Figure object """ if str(type(figure)) == "<class 'matplotlib.axes._subplots.AxesSubplot'>": ax = figure figure = figure.figure elif str(type(figure)) == "<class 'matplotlib.figure.Figure'>": ax = figure.axes[0] else: msg = 'object must be a matplotlib.AxesSubplot or matplotlib.Figure object' raise TypeError(msg) if len(figure.axes) != 1: msg = 'matplotlib.figure object includes more than one axes' raise TypeError(msg) ax.set_title(self.title) ax.set_xlabel(self.xlabel) ax.set_ylabel(self.ylabel) ax.set_xlim(self.xlim[0], self.xlim[1]) ax.set_ylim(self.ylim[0], self.ylim[1]) ax.grid(color=self.grid_color, linestyle=self.grid_linestyle, linewidth=self.grid_linewidth) ax.grid(self.grid) return figure
Example #4
Source File: visualization.py From chemml with BSD 3-Clause "New" or "Revised" License | 5 votes |
def plot(self, dfx, x): """ the main function to plot based on the input dataframe and its header Parameters ---------- dfx: pandas dataframe the x axis data x: string or integer, optional (default=0) header or position of data in the dfx Returns ------- matplotlib.figure.Figure object """ # check data if isinstance(x, str): X = dfx[x].values elif isinstance(x, int): X = dfx.iloc[:, x].values else: msg = 'x must be string for the header or integer for the postion of data in the dfx' raise TypeError(msg) # instantiate figure fig = plt.figure() ax = fig.add_subplot(111) tash = ax.hist(X, bins= self.bins, color=self.color, **self.kwargs) return fig
Example #5
Source File: plotter.py From TriFusion with GNU General Public License v3.0 | 4 votes |
def interpolation_plot(data, title=None, ax_names=None): """Creates black and white interpolation plot Creates a black and white interpolation plot from data, which must consist of a 0/1 matrix for absence/presence of taxa in genes. Parameters ---------- data : numpy.array Single or multi-dimensional array with plot data. title : str Title of the plot. ax_names : list List with the labels for the x-axis (first element) and y-axis (second element). Returns ------- fig : matplotlib.pyplot.Figure Figure object of the plot. _ : None Placeholder for the legend object. Not used here but assures consistency across other plotting methods. _ : None Placeholder for the table header list. Not used here but assures consistency across other plotting methods. """ plt.rcParams["figure.figsize"] = (8, 6) # Use ggpot style plt.style.use("ggplot") fig, ax = plt.subplots() # Setting the aspect ratio proportional to the data ar = float(len(data[0])) / float(len(data)) * .2 ax.imshow(data, interpolation="none", cmap="Greys", aspect=ar) ax.grid(False) return fig, None, None
Example #6
Source File: plotter.py From TriFusion with GNU General Public License v3.0 | 4 votes |
def outlier_densisty_dist(data, outliers, outliers_labels=None, ax_names=None, title=None): """Creates a density distribution for outlier plots. Parameters ---------- data : numpy.array 1D array containing data points. outliers : numpy.array 1D array containing the outliers. outliers_labels : list or numpy.array 1D array containing the labels for each outlier. title : str Title of the plot. Returns ------- fig : matplotlib.Figure Figure object of the plot. lgd : matplotlib.Legend Legend object of the plot. table : list Table data in list format. Each item in the list corresponds to a table row. """ plt.rcParams["figure.figsize"] = (8, 6) fig, ax = plt.subplots() # Create density function sns.distplot(data, rug=True, hist=False, color="black") # Plot outliers ax.plot(outliers, np.zeros_like(outliers), "ro", clip_on=False, label="Outliers") # Create legend lgd = ax.legend(frameon=True, loc=2, fancybox=True, shadow=True, framealpha=.8, prop={"weight": "bold"}) if outliers_labels: table = [[os.path.basename(x)] for x in outliers_labels] else: table = None return fig, lgd, table
Example #7
Source File: visualization.py From chemml with BSD 3-Clause "New" or "Revised" License | 4 votes |
def plot(self,dfx,dfy,x,y): """ the main function to plot based on the input dataframes and their headers Parameters ---------- dfx: pandas dataframe the x axis data dfy: pandas dataframe the y axis data x: string or integer, optional (default=0) header or position of data in the dfx y: string or integer, optional (default=0) header or position of data in the dfy Returns ------- matplotlib.figure.Figure object """ # check data if isinstance(x,str): X = dfx[x].values elif isinstance(x,int): X = dfx.iloc[:,x].values else: msg = 'x must be string for the header or integer for the postion of data in the dfx' raise TypeError(msg) if isinstance(y, str): Y = dfy[y].values elif isinstance(y, int): Y = dfy.iloc[:, y].values else: msg = 'y must be string for the header or integer for the postion of data in the dfy' raise TypeError(msg) # instantiate figure fig = plt.figure() ax = fig.add_subplot(111) trash = ax.plot(X,Y,color=self.color, marker=self.marker, linestyle=self.linestyle, linewidth= self.linewidth) return fig