Plotting Modules
Plotting and summary of TopoStats output statistics.
TopoSum
Class for summarising grain statistics in plots.
Parameters
df : pd.DataFrame Pandas data frame of data to be summarised. base_dir : str | Path Base directory from which all paths are relative to. csv_file : str | Path CSV file of data to be summarised. stat_to_sum : str Variable to summarise. molecule_id : str Variable that uniquely identifies molecules. image_id : str Variable that uniquely identifies images. hist : bool Whether to plot histograms. stat : str Statistic to plot on histogram 'count' (default), 'freq'. bins : int Number of bins to plot. kde : bool Whether to include a Kernel Density Estimate. cut : float = 20, Cut point for KDE. figsize : tuple Figure dimensions. alpha : float Opacity to use in plots. palette : str = "deep" Seaborn colour plot to use. savefig_format : str File type to save plots as 'png' (default), 'pdf', 'svg'. output_dir : str | Path Location to save plots to. var_to_label : dict Variable to label dictionary for automatically adding titles to plots. hue : str Dataframe column to group plots by.
Source code in topostats/plotting.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
__init__(df=None, base_dir=None, csv_file=None, stat_to_sum=None, molecule_id='grain_number', image_id='image', hist=True, stat='count', bins=12, kde=True, cut=20, figsize=(16, 9), alpha=0.5, palette='deep', savefig_format='png', output_dir='.', var_to_label=None, hue='basename')
Initialise the class.
Parameters
df : pd.DataFrame Pandas data frame of data to be summarised. base_dir : str | Path Base directory from which all paths are relative to. csv_file : str | Path CSV file of data to be summarised. stat_to_sum : str Variable to summarise. molecule_id : str Variable that uniquely identifies molecules. image_id : str Variable that uniquely identifies images. hist : bool Whether to plot histograms. stat : str Statistic to plot on histogram 'count' (default), 'freq'. bins : int Number of bins to plot. kde : bool Whether to include a Kernel Density Estimate. cut : float = 20, Cut point for KDE. figsize : tuple Figure dimensions. alpha : float Opacity to use in plots. palette : str = "deep" Seaborn colour plot to use. savefig_format : str File type to save plots as 'png' (default), 'pdf', 'svg'. output_dir : str | Path Location to save plots to. var_to_label : dict Variable to label dictionary for automatically adding titles to plots. hue : str Dataframe column to group plots by.
Source code in topostats/plotting.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
melt_data(df, stat_to_summarize, var_to_label)
staticmethod
Melt a dataframe into long format for plotting with Seaborn.
Parameters
df : pd.DataFrame Statistics to melt. stat_to_summarize : str Statistics to summarise. var_to_label : dict Mapping of variable names to descriptions.
Returns
pd.DataFrame Data in long-format with descriptive variable names.
Source code in topostats/plotting.py
save_plot(outfile)
Save the plot to the output_dir.
Parameters
outfile : str Output file name to save figure to.
Source code in topostats/plotting.py
set_palette()
set_xlim(percent=0.1)
Set the range of the x-axis.
Parameters
percent : float Percentage of the observed range by which to extend the x-axis. Only used if supplied range is outside the observed values.
Source code in topostats/plotting.py
sns_plot()
Plot the distribution of one or more statistics as either histogram, kernel density estimates or both.
Uses base Seaborn.
Returns
Optional[Union[Tuple[plt.Figure, plt.Axes], None]] Tuple of Matplotlib figure and axes if plotting is successful, None otherwise.
Source code in topostats/plotting.py
sns_violinplot()
Violin plot of data.
Returns
fig, ax Matplotlib fig and ax objects.
Source code in topostats/plotting.py
plot_crossing_linetrace_halfmax(branch_stats_dict, mask_cmap, title)
Plot the height-map line traces of the branches found in the 'branch_stats' dictionary, and their meetings.
Parameters
branch_stats_dict : dict Dictionary containing branch height, distance and fwhm info. mask_cmap : matplotlib.colors.Colormap Colormap for plotting. title : str Title for the plot.
Returns
fig, ax Matplotlib fig and ax objects.
Source code in topostats/plotting.py
plot_height_profiles(height_profiles)
Plot height profiles.
Parameters
height_profiles : npt.NDArray Single height profile (1-D numpy array of heights) or array of height profiles. If the later the profiles plot will be overlaid.
Returns
tuple Matplotlib.pyplot figure object and Matplotlib.pyplot axes object.
Source code in topostats/plotting.py
run_toposum(args=None)
Run Plotting.
Parameters
args : None Arguments to pass and update configuration.
Source code in topostats/plotting.py
toposum(config)
Process plotting and summarisation of data.
Parameters
config : dict Dictionary of summarisation options.
Returns
dict Dictionary of nested dictionaries. Each variable has its own dictionary with keys 'dist' and 'violin' which contain distribution like plots and violin plots respectively (if the later are required). Each 'dist' and 'violin' is itself a dictionary with two elements 'figures' and 'axes' which correspond to MatplotLib 'fig' and 'ax' for that plot.
Source code in topostats/plotting.py
handler: python options: docstring_style: numpy rendering: show_signature_annotations: true