Python Automation and Machine Learning for EM and ICs

An Online Book, Second Edition by Dr. Yougui Liao (2024)

Python Automation and Machine Learning for EM and ICs - An Online Book

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

Plot Cheatsheet

Table 3447. Plot cheatsheet.

Application Details

ax.set_xlim(0, 6) # Set plot limits

ax.set_ylim(0, 4) # Set plot limits

# Set axes limits explicitly

x_min, x_max = min(x), max(x)

y_min, y_max = min(y), max(y)

plt.xlim(x_min - 0.1 * (x_max - x_min), x_max + 0.1 * (x_max - x_min))

plt.ylim(y_min, y_max * 1.1) # This will extend the y-axis to add space at the top

 
ax.axis('off') # Turn off axes  

plt.title('Workflow', fontsize=16, color='darkblue')

 
draw_arrow(3.3, 2, 0.4, 1, 'Group By Key', text_color='red') Change text color
Adjusting space around the plot with dummy categories df.loc[-1] = ['', np.nan]
df.loc[len(df)] = ['', np.nan]
.xticks() and .yticks() labels = ['Liao', 'Global', 'Sino', 'Best']
plt.xticks(x, labels, rotation ='vertical')
Layout of plotting multiple images by hiding frame/border  
Plot tables  
plt.savefig()  
Modify x-tick labels Remove the "feature_" from the x-tick labels
Plot from dictionary  
Plot images from dataframe from CSVs  
Plot image with text label on image  
Plot histogram with seaborn, pie, histogram  
Transparency of marker  
Second x-axis tick label (dual label)  
Arrow annotation (.annotate())  
Box and whisker plots  
Select columns to plot, plot from dataframe  
Plot with specific (e.g. first and remaining) columns of DataFrame for x- and y-axis  
Waterfall plot  
ax.axis('on')  
Plot curves  
Arrow annotation: .annotate('Point A', xy=(a, a), xytext=(a+4, a)  
Avoid plot mixture: plt.close()  
Plot with x- and y- intensity of image  
fig.add_trace(go.Bar(x=[3, 5, 10], y=[20, 7, 10]))  
Plot from dictionary  
plt.margins(0.2), white area on image frame/edge: plt.savefig(imageFile, bbox_inches='tight')

# Pad margins so that markers don't get clipped by the axes

plt.margins(x=0.1, y=0.1)

plt.subplots_adjust(bottom = 0.25), plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None), or plt.subplots_adjust(wspace=0, hspace=0)  
plt.xticks(x, labels, rotation ='vertical')  
matplotlib.pyplot axis/text color (xticks, rotation, xlabel, ylabel, title, fontsize, grid(), legend(), show())  
Partial (e.g. first portion) of headers of a DataFrame  
Font size of tick labels  
dot size color: plt.scatter(X, Y2, color='black', label='', s=300)  
Set logarithmic scale (exponential) for y-axis  
Crop images: image[y:h, x:w]  
Figure size in plotted image  
Highlight the plotted dots uncer certain condition  
Generating heatmaps for grouped data occurrences  
Heatmap  
Plot a heatmap with three columns of data  
Fit and smooth plotted curves  
Least squares fit  
Colored scatter plot  
Merge two dataframes with two columns from each dataframe, and then plot the data  
plt.xticks(range(min(x), max(x) + 1, 3)) Generates a sequence of numbers starting from the minimum value in the list x, ending at the maximum value in x (inclusive because of the + 1), with a step size of 3, for setting the x-axis ticks at intervals of 3.
plt.bar(my_list, new_y_values, label=f'Data from DataFrame {idx}')
Bar plot
plt.plot(my_list, new_y_values, marker='o', linestyle='-', label=f'Data from DataFrame {idx}')
Line-dot plot
plot with x- and y-list ; plot from list , plot from list, plot from list