Frame Plotting¶
This provides a simple high-level interface of plotting a frame.
To start
f = Frame2D.from_image("path/to/file.png")
fpl = f.plot()
This gives you a Frame2DPlot object to call plotting functions with.
If you only want to plot a few indexes, you can call it with arguments
from sklearn.preprocessing import robust_scale,
f = Frame2D.from_image("path/to/file.png")
fpl = f.plot([0, 1])
If the file is an RGB image, it’ll just plot with R and G only.
There are multiple ways to generate the plots, listed in the Module Info.
Setting Subplot Shape¶
By default, if Frame2DPlot.subplot_shape is None, it’ll find the best shape to fit the plot.
However, if you want to set a fixed shape, you can do so
ROWS = 3
COLS = 2
fpl.subplot_shape = (ROWS, COLS)
Setting Titles¶
By default, if Frame2DPlot.titles is None, it’ll generate titles of Index 0, Index 1, … and so on.
If you do set the title, take note that the number of titles must match the number of channels, else an
AssertionError will be thrown.
Example¶
Here, we load in an image on 25% scale then plot the images with 22 rows and 1 column.
SCALE = 0.25
f = Frame2D.from_image("path/to/file.png", scale=SCALE)
fc = f.get_all_chns()
fpl = fc.plot()
ROWS = 22
COLS = 1
PLT_SCALE = 1.1
fpl.subplot_shape = (ROWS, COLS)
fpl.image(scale=PLT_SCALE)
plt.show()
Module Info¶
-
class
frmodel.base.D2.frame._frame_plot.Frame2DPlot(f: Frame2D, subplot_shape: tuple = None, titles: list = None)¶ Bases:
object-
_create_grid(scale: float = 1.0)¶ Facilitates in create a subplot grid for plotting functions.
- Parameters
scale – Scale of the plot
- Returns
An Axes reference generator
-
hist(scale=1, bins=50)¶ For each index, create a separate subplot hist.
- Parameters
scale – Scale of the subplots
bins – Number of bins to pass into hist
- Returns
A plt.Figure
-
image(scale: float = 1, colormap: str = 'magma')¶ For each index, create a separate subplot imshow.
- Parameters
scale – Scale of the subplots
colormap – The cmap of imshow. See plt.imshow for available cmaps.
- Returns
A plt.Figure
-
kde(scale=1, smoothing=0.5)¶ For each index, create a separate subplot hist.
Note: smoothing may not work on some versions of seaborn.
- Parameters
scale – Scale of the subplots
smoothing – The amount of smoothing to apply to the KDE
- Returns
A plt.Figure
-
scatter3d(chn: frmodel.base.consts.CONSTS.CHN, colored: bool = False, z_scale: int = 1, point_size: float = 7, sample_size: int = 10000, colorscale=['#440154', '#482878', '#3e4989', '#31688e', '#26828e', '#1f9e89', '#35b779', '#6ece58', '#b5de2b', '#fde725'])¶ Plot a single index with respect to its X and Y.
- Parameters
chn – A single channel.
colored – Whether to have the point cloud coloured with RGB channels. Only works if RGB exists.
z_scale – The scale of the Z Axis. If lower than 1, it’ll look flatter, vice versa.
point_size – The size of the markers.
sample_size – The amount of points to sample. If None, use all points
colorscale – The color scale to use when plotting.
- Returns
A plt.Figure
-
static
set_browser_plotting()¶ Makes Plotly render on browser by changing the flag.
-
surface3d(chn: frmodel.base.consts.CONSTS.CHN, nan_value: float = 0)¶ Plots a surface 3d plot on Plotly
- Parameters
chn – The channel to plot as height
nan_value – The value to replace NaNs
-