<jupyter_start><jupyter_text>Draw Shapes in Matplotlib> Draw Shapes in Matplotlib- toc: true - badges: true- comments: true- categories: [matplotlib]- image: images/chart-preview.png  1. Install openFoam<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
#from matplotlib.patches import Polygon, Circle, Rectangle, Wedge
fig, (ax1) = plt.subplots(1, 1, figsize =(7, 7))
ax1.patches.append(mpatches.Circle([0.2, 0.8], 0.05, transform=fig.transFigure))
ax1.patches.append(mpatches.Rectangle((0.15, 0.58), 0.15, 0.15, transform=fig.transFigure))
ax1.patches.append(mpatches.Rectangle((0.15, 0.45), 0.20, 0.10, transform=fig.transFigure))
y = np.array([[0.15,0.35], [0.4,0.35], [0.15,0.42]])
ax1.patches.append(mpatches.Polygon(y, transform=fig.transFigure))

y = np.array([[0.20,0.20], [0.4,0.20], [0.5,0.32], [0.13, 0.30], [0.20,0.20]])
ax1.patches.append(mpatches.Polygon(y, transform=fig.transFigure))


y = np.array([[0.10,0.20], [0.4,0.20], [0.5,0.32], [0.13, 0.30], [0.20,0.20]])
ax1.patches.append(mpatches.Polygon(y, transform=fig.transFigure))

ax1.patches.append(mpatches.Rectangle((0.15, 0.15), 0.20, 0.025, transform=fig.transFigure))
# combinations

ax1.patches.append(mpatches.Rectangle((0.65, 0.62), 0.15, 0.15, transform=fig.transFigure))
ax1.patches.append(mpatches.Circle([0.75, 0.8], 0.05, transform=fig.transFigure))

ax1.patches.append(mpatches.Circle([0.75, 0.45], 0.04, transform=fig.transFigure))
ax1.patches.append(mpatches.Circle([0.75, 0.50], 0.05, transform=fig.transFigure))
ax1.patches.append(mpatches.Circle([0.70, 0.50], 0.05, transform=fig.transFigure))

y = np.array([[0.65,0.15], [0.75,0.15], [0.65,0.4]])
ax1.patches.append(mpatches.Polygon(y, transform=fig.transFigure))
ax1.patches.append(mpatches.Circle([0.70, 0.30], 0.05, transform=fig.transFigure))
ax1.patches.append(mpatches.Rectangle((0.65, 0.2), 0.20, 0.025, transform=fig.transFigure))

#plt.axis('off')
plt.xticks([])
plt.yticks([])
plt.savefig("shapes.png", dpi = 300)
fig, (ax1) = plt.subplots(1, 1,figsize = (7,7))
ax1.set_xlim(0,1)
ax1.set_ylim(0,1)
ax1.patches.append(mpatches.Rectangle((0.23, 0.4), 0.55, 0.3, transform=fig.transFigure,\
                                      edgecolor = 'k', facecolor = "None", lw = 2))
y = np.array([[0.40,0.45], [0.50,0.45], [0.45,0.4]])
#ax1.patches.append(mpatches.Polygon(y, transform=fig.transFigure))

ax1.patches.append(mpatches.Circle([0.45, 0.55], 0.05, transform=fig.transFigure))
ax1.patches.append(mpatches.Rectangle([0.45, 0.55], 0.10,0.10, transform=fig.transFigure))
#ax1.patches.append(mpatches.Rectangle((0.4, 0.4), 0.20, 0.025, transform=fig.transFigure))
y_list = [0.4,  0.50,  0.60, 0.70]
for _, y in enumerate(y_list):
    ax1.arrow(0.135, y, 0.115, 0, length_includes_head=True,
          head_width=0.03, head_length=0.02) 
    #ax1.arrow(0.85, y, 0.1, 0, length_includes_head=True,
    #      head_width=0.03, head_length=0.02)     
ax1.text(0.139, 0.65, "U = const")    
ax1.text(0.72, 0.7, "p = 0 bar")
ax1.text(0.45, 0.78, "no slip") 
ax1.axis('off')
plt.savefig("BCs.png", dpi = 300)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20965164589325663, 'fraction_numerical': 0.11760945989133909, 'mean_word_length': 4.785582255083179, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '253037', 'license': 'Apache-2.0', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1368, 'n_words': 209, 'path': '_notebooks/2021-02-09-drawShapes.ipynb', 'repo_name': 'simsisim/sims-blog', 'size': '3129'}