import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Rectangle, Circle, FancyBbox import matplotlib.patches as mpatches def draw_demulsifier_diagram(): """Create a visualization of demulsifier separating water and salt from crude oil""" # Set up the figure fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 8)) fig.suptitle('Role of Demulsifiers in Crude Oil Separation Process', fontsize=16, fontweight='bold', y=0.98) # Colors oil_color = '#8B7355' # Brown for crude oil water_color = '#1E90FF' # Dodger blue for water salt_color = '#F0F0F0' # Light gray for salt demulsifier_color = '#FF6B6B' # Coral red for demulsifier # ========== LEFT PANEL: Before Demulsifier ========== ax1.set_title('Before Demulsifier Addition', fontsize=14, fontweight='bold', pad=20) ax1.set_xlim(0, 10) ax1.set_ylim(0, 10) ax1.set_aspect('equal') ax1.axis('off') # Draw the oil container container = Rectangle((1, 1), 8, 7, linewidth=2, edgecolor='black', facecolor='none') ax1.add_patch(container) # Draw emulsion mixture emulsion_height = 6 emulsion = Rectangle((1, 2), 8, emulsion_height, linewidth=0, edgecolor='none', facecolor=oil_color, alpha=0.3) ax1.add_patch(emulsion) # Draw water droplets (dispersed phase) np.random.seed(42) for _ in range(30): x = np.random.uniform(1.5, 8.5) y = np.random.uniform(2.5, 7.5) radius = np.random.uniform(0.1, 0.3) droplet = Circle((x, y), radius, facecolor=water_color, edgecolor='darkblue', alpha=0.7) ax1.add_patch(droplet) # Add salt crystals inside some water droplets if np.random.random() > 0.7: salt_size = radius * 0.5 salt = Rectangle((x - salt_size/2, y - salt_size/2), salt_size, salt_size, facecolor=salt_color, edgecolor='gray', linewidth=1) ax1.add_patch(salt) # Add labels ax1.text(5, 8.5, 'Emulsion: Water-in-Oil', ha='center', fontsize=12, fontweight='bold') ax1.text(2.5, 1.5, 'Stable mixture\nWater droplets dispersed in oil', ha='center', fontsize=10, style='italic') # Add legend for left panel left_legend_elements = [ mpatches.Patch(color=oil_color, alpha=0.3, label='Crude Oil'), mpatches.Patch(color=water_color, alpha=0.7, label='Water Droplets'), mpatches.Patch(color=salt_color, label='Salt Crystals'), ] ax1.legend(handles=left_legend_elements, loc='lower center', bbox_to_anchor=(0.5, -0.05)) # ========== RIGHT PANEL: After Demulsifier ========== ax2.set_title('After Demulsifier Addition', fontsize=14, fontweight='bold', pad=20) ax2.set_xlim(0, 10) ax2.set_ylim(0, 10) ax2.set_aspect('equal') ax2.axis('off') # Draw the oil container container2 = Rectangle((1, 1), 8, 7, linewidth=2, edgecolor='black', facecolor='none') ax2.add_patch(container2) # Draw separated layers water_layer = Rectangle((1, 1), 8, 2, linewidth=0, facecolor=water_color, alpha=0.8) oil_layer = Rectangle((1, 3), 8, 4, linewidth=0, facecolor=oil_color, alpha=0.6) interface = Rectangle((1, 3), 8, 0.1, linewidth=0, facecolor='black', alpha=0.3) ax2.add_patch(water_layer) ax2.add_patch(oil_layer) ax2.add_patch(interface) # Draw salt sediment at bottom salt_layer = Rectangle((1, 1), 8, 0.3, linewidth=0, facecolor=salt_color, edgecolor='gray') ax2.add_patch(salt_layer) # Draw demulsifier molecules at interface for i in range(8): x = 1.5 + i * 1 # Demulsifier molecule (simplified as small circles at interface) demuls = Circle((x, 3), 0.15, facecolor=demulsifier_color, edgecolor='darkred', linewidth=1) ax2.add_patch(demuls) # Add arrows showing demulsifier action ax2.arrow(5, 9, 0, -2, head_width=0.3, head_length=0.3, fc=demulsifier_color, ec=demulsifier_color, linewidth=2) ax2.text(5.5, 8.5, 'Demulsifier', color=demulsifier_color, fontsize=11, fontweight='bold') # Add labels for layers ax2.text(5, 5.5, 'Clean Crude Oil', ha='center', fontsize=11, fontweight='bold', color='white') ax2.text(5, 2.0, 'Separated Water', ha='center', fontsize=11, fontweight='bold', color='white') ax2.text(5, 1.15, 'Salt Sediment', ha='center', fontsize=10, fontweight='bold', color='black') # Add interface label ax2.text(5, 3.2, 'Interface with Demulsifiers', ha='center', fontsize=9, style='italic', color=demulsifier_color) # Add legend for right panel right_legend_elements = [ mpatches.Patch(color=oil_color, alpha=0.6, label='Separated Oil'), mpatches.Patch(color=water_color, alpha=0.8, label='Separated Water'), mpatches.Patch(color=salt_color, label='Salt Sediment'), mpatches.Patch(color=demulsifier_color, label='Demulsifier Molecules'), ] ax2.legend(handles=right_legend_elements, loc='lower center', bbox_to_anchor=(0.5, -0.05)) # ========== Add explanatory text ========== explanation_text = ( "Demulsifiers are surface-active chemicals that break water-in-oil emulsions by:\n" "1. Migrating to the oil-water interface\n" "2. Displacing natural emulsifiers\n" "3. Promoting droplet coalescence\n" "4. Allowing gravity separation of water and salt" ) fig.text(0.5, 0.02, explanation_text, ha='center', fontsize=11, bbox=dict(boxstyle="round,pad=0.5", facecolor='lightyellow', alpha=0.8)) plt.tight_layout() return fig, ax1, ax2 # Generate and display the diagram fig, ax1, ax2 = draw_demulsifier_diagram() # Save high-quality image plt.savefig('demulsifier_process.png', dpi=300, bbox_inches='tight', facecolor='white') plt.show() print("Diagram has been created and saved as 'demulsifier_process.png'") print("\nKey components shown:") print("1. Left panel: Water-in-oil emulsion with dispersed water droplets containing salt") print("2. Right panel: Separated layers after demulsifier addition") print("3. Demulsifier molecules at the interface facilitating separation")
21.12.2025 14:35