Untitled

 avatar
unknown
plain_text
a year ago
2.6 kB
4
Indexable
import matplotlib.pyplot as plt
import matplotlib.patches as patches

# Create a figure and axis
fig, ax = plt.subplots(figsize=(10, 6))

# Define colors and positions
colors = {
    'Cu': 'brown',
    'H': 'blue',
    'N': 'green',
    'O': 'red'
}

positions = {
    'Cu': (1, 4),
    'HNO3_1': [(3, 5), (4, 5), (5, 5)],
    'HNO3_2': [(3, 4.5), (4, 4.5), (5, 4.5)],
    'HNO3_3': [(3, 4), (4, 4), (5, 4)],
    'HNO3_4': [(3, 3.5), (4, 3.5), (5, 3.5)],
    'Cu2+': (7, 4),
    'NO3_1': [(9, 4.5), (10, 4.5), (11, 4.5)],
    'NO3_2': [(9, 3.5), (10, 3.5), (11, 3.5)],
    'NO2_1': [(13, 5), (14, 5)],
    'NO2_2': [(13, 4), (14, 4)],
    'H2O_1': [(16, 5), (17, 5)],
    'H2O_2': [(16, 4), (17, 4)]
}

# Draw reactants (Before)
# Cu
ax.add_patch(patches.Circle(positions['Cu'], 0.3, color=colors['Cu'], label='Cu'))
ax.text(*positions['Cu'], 'Cu', ha='center', va='center', color='white')

# HNO3 molecules
for i in range(1, 5):
    for idx, atom in enumerate(['H', 'N', 'O']):
        x, y = positions[f'HNO3_{i}'][idx]
        ax.add_patch(patches.Circle((x, y), 0.3, color=colors[atom]))
        ax.text(x, y, atom, ha='center', va='center', color='white')

# Draw products (After)
# Cu2+
ax.add_patch(patches.Circle(positions['Cu2+'], 0.3, color=colors['Cu'], label='Cu2+'))
ax.text(*positions['Cu2+'], 'Cu2+', ha='center', va='center', color='white')

# NO3- molecules
for i in range(1, 3):
    for idx, atom in enumerate(['N', 'O', 'O']):
        x, y = positions[f'NO3_{i}'][idx]
        ax.add_patch(patches.Circle((x, y), 0.3, color=colors[atom]))
        ax.text(x, y, atom, ha='center', va='center', color='white')

# NO2 molecules
for i in range(1, 3):
    for idx, atom in enumerate(['N', 'O']):
        x, y = positions[f'NO2_{i}'][idx]
        ax.add_patch(patches.Circle((x, y), 0.3, color=colors[atom]))
        ax.text(x, y, atom, ha='center', va='center', color='white')

# H2O molecules
for i in range(1, 3):
    for idx, atom in enumerate(['H', 'O']):
        x, y = positions[f'H2O_{i}'][idx]
        ax.add_patch(patches.Circle((x, y), 0.3, color=colors[atom]))
        ax.text(x, y, atom, ha='center', va='center', color='white')

# Add labels for sections
ax.text(2, 6, 'Before Reaction', ha='center', fontsize=12, fontweight='bold')
ax.text(14, 6, 'After Reaction', ha='center', fontsize=12, fontweight='bold')

# Set limits, aspect ratio, and remove axes
ax.set_xlim(0, 18)
ax.set_ylim(2, 7)
ax.set_aspect('equal')
ax.axis('off')

# Show the plot
plt.show()
Editor is loading...
Leave a Comment