Visualization module
- The chemml.visualization module includes (please click on links adjacent to function names for more information):
scatter2D:
scatter2D()
hist:
hist()
decorator:
decorator()
SavePlot:
SavePlot()
- class chemml.visualization.SavePlot(filename, output_directory=None, format='png', kwargs={})
Accepts a matplotlib AxesSubplot object and saves the figure with distinct options and at a specific location. Displays the path to the saved figure.
- filename: string
name of the file that needs to be saved
- output_directory: string, optional (default=None)
specify the folder where the figure needs to be saved. If the output directory that is specified does not exist, a new directory is created.
- format: string, optional (default=’png’)
format of the figure that needs to be saved. Note: we recommend ‘eps’ for publication quality
- kwargsdictionary, optional (default = {})
add any matplotlib options in the form of a dictionary. provide keys in the form of a string. for example kwargs = {‘key’:value} https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure.savefig
>>> from chemml.datasets import load_cep_homo >>> from chemml.visualization import SavePlot >>> smiles, homo = load_cep_homo() >>> ax = homo.plot(kind='hist') >>> sa=SavePlot(filename='homo',output_directory='plots',kwargs={'facecolor':'w','dpi':100,'pad_inches':0.1, 'bbox_inches':'tight'}) >>> sa.save(obj=ax,main_directory='project') The Plot has been saved at: project/plots/homo.png
- save(obj, main_directory='.')
This is the main function that saves the figure.
- obj: matplotlib.axes._subplots.AxesSubplot or matplotlib.figure.Figure
contains information about the plot
- main_directory: string, optional (default = ‘.’)
specify the parent directory where the folder needs to be saved.
- class chemml.visualization.decorator(title='', xlabel='', ylabel='', xlim=(None, None), ylim=(None, None), grid=True, grid_color='k', grid_linestyle='--', grid_linewidth=0.5)
This class provides options to decorate a plot with more information.
- title: string, optional (default=’’)
title
- xlabel: string, optional (default=’’)
the x axis label
- ylabel: string, optional (default=’’)
the y axis label
- xlim: tuple, optional (default=(None, None))
a tuple of min and max of x axis
- ylim: tuple, optional (default=(None, None))
a tuple of min and max of y axis
- grid: boolean, optional (default=True)
axes grids can be on (True) or off (False) check: https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.grid.html
- gridcolor: string, optional (default=’k’)
set grid color check this link: https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_linestyle
- grid_linewidth: float, optional (default=2)
set grid line width check this link: https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_linewidth
>>> from chemml.visualization import hist, decorator >>> from chemml.datasets import load_organic_density >>> smiles, density, features = load_organic_density() >>> hg = hist(20,'g',{'normed':True}) >>> fig = hg.plot(features,'AMW') # atomic molecular weights >>> dec = decorator('histogram',xlabel='density', ylabel='%', xlim=(4,None), ylim=(0,None), grid=True, grid_color='g', grid_linestyle=':', grid_linewidth=0.5) >>> fig = dec.fit(fig) >>> fig.show()
- fit(figure)
the main function to fit the parameters to the input figure
- figure: matplotlib.figure.Figure object or matplotlib.AxesSubplot object
this function only proceed with one set of axes in the figure.
matplotlib.figure.Figure object
- matplotlib_font(family='DejaVu Sans', size=18, weight='normal', style='normal', variant='normal')
The matplotlib_font function sets custom font properties.
Changing these parameters wil affect all the plots in your working session.
- family: string, optional (default = ‘normal’)
check this example: https://matplotlib.org/examples/pylab_examples/fonts_demo.html
- size: integer or string, optional (default = 18)
check this example: https://matplotlib.org/examples/pylab_examples/fonts_demo.html
- weight: string, optional (default = ‘normal’)
check this example: https://matplotlib.org/examples/pylab_examples/fonts_demo.html
- style: string, optional (default = ‘normal’)
check this example: https://matplotlib.org/examples/pylab_examples/fonts_demo.html
- variant: string, optional (default = ‘normal’)
check this example: https://matplotlib.org/examples/pylab_examples/fonts_demo.html
- class chemml.visualization.hist(bins=None, color=None, kwargs={})
The histogram plotting interface. It is built on top of the matplotlib.pyplot.hist function . check this link: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html#matplotlib.pyplot.hist
- bins: integer or sequence or ‘auto’, optional (default = None)
exact same parameter from matplotlib.pyplot.hist
- color: color or array_like of colors or None, optional (default = None)
exact same parameter from matplotlib.pyplot.hist
- kwargsdictionary, optional (default = {})
add any matplotlib.pyplot.hist parameter in the form of a dictionary. check this link: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html#matplotlib.pyplot.hist
provide keys in the form of a string. for example kwargs = {‘key’:value}
>>> from chemml.visualization import hist >>> from chemml.datasets import load_organic_density >>> smiles, density, features = load_organic_density() >>> hg = hist(20,'g',{'normed':True}) >>> fig = hg.plot(features,'AMW') # atomic molecular weights >>> fig.show()
- plot(dfx, x)
the main function to plot based on the input dataframe and its header
- dfx: pandas dataframe
the x axis data
- x: string or integer, optional (default=0)
header or position of data in the dfx
matplotlib.figure.Figure object
- class chemml.visualization.scatter2D(color='b', marker='.', linestyle='', linewidth=2)
The scatter 2D plotting interface. It is built on top of the matplotlib.pyplot.plot function.
- color: string, optional (default=’b’)
set color check this link Notes for available options: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot
- marker: string, optional (default=’.’)
set marker check this link Notes for available options: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot
- linestyle: string, optional (default=’’)
set line style check this link: https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_linestyle
- linewidth: float, optional (default=2)
set line width check this link: https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_linewidth
>>> from chemml.visualization import scatter2D >>> from chemml.datasets import load_organic_density >>> smiles, density, features = load_organic_density() >>> sc = scatter2D('r', marker='.') >>> fig = sc.plot(dfx=den, dfy=fea, x=0, y=1) >>> fig.show()
- plot(dfx, dfy, x, y)
the main function to plot based on the input dataframes and their headers
- 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
matplotlib.figure.Figure object