Electron microscopy
 
PythonML
Generating Heatmaps for Grouped Data Occurrences
- Python Automation and Machine Learning for ICs -
- An Online Book: Python Automation and Machine Learning for ICs by Yougui Liao -
Python Automation and Machine Learning for ICs                                                           http://www.globalsino.com/ICs/        


Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

=================================================================================

Generating heatmaps for grouped data occurrences. Code:

         

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Input:    

         

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Output:    

         

This script is designed to visualize data from a CSV file by generating heatmaps that display the occurrences of "X" and "Y" pairs within specific subgroups of the dataset. The data is grouped by three columns: 'Name', 'Z', and 'Grades', creating subgroups within the dataset. For each subgroup, it computes a pivot table to aggregate the occurrences of each "X" and "Y" pair, using 'X' values as columns, 'Y' values as rows, and counting the number of occurrences as the cell values. Missing pairs (i.e., those not appearing in the subgroup) are filled with 0 to indicate their absence.

A heatmap is then plotted for each subgroup with seaborn, using the viridis color map to visually represent the count of occurrences. Annotations on the heatmap display the exact counts, making it easy to identify the frequency of each "X" and "Y" pair within the subgroup. Each heatmap is accompanied by a title that includes the subgroup's 'Name', 'Z', and 'Grades' values, along with labels for the 'X' and 'Y' axes, enhancing clarity and interpretability.

===========================================

Cells with a value of 0 have no color fill and no text annotation when generating heatmaps for grouped data occurrences. Code:

Input file is the same as the one above, but an output example is below:

===========================================

Plot heatmap under condition that any missing pairs in the data are represented with 0 occurrences. Code:

         

Input:

Output:

And other maps.

In this script, we create a full grid of x- and y-coordinates in the ranges specified (0 to 15 for x, and 0 to 20 for y) and ensure that any missing pairs in our data are represented with 0 occurrences: a) Generate a complete grid of x- and y-coordinates within our specified ranges, b) Merge this grid with our existing data, filling in 0 for any x-y pair that does not exist in your data, and c) Adjust the script to use this complete dataset for generating the heatmap.

Note if we do not want to stop displaying annotations (numbers), then we can change the corresponding code to the one below:

plt.figure(figsize=(10, 8))
sns.heatmap(full_pivot_table, cmap='viridis', mask=mask, cbar=False)

===========================================

Plot heatmap under condition that any missing pairs in the data are represented with 0 occurrences, and the 'X' values are shifted 5 units in the negative direction and the 'Y' values are shifted 5 units in the positive direction by applying transformations to these columns after generating the xy_grid DataFrame but before merging it with the grouped data. Code:

Output:

 

 

 


         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         

 

 

 

 

 



















































 

 

 

 

 

=================================================================================