-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotter.py
More file actions
140 lines (110 loc) · 4.73 KB
/
plotter.py
File metadata and controls
140 lines (110 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<<<<<<< HEAD
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
import pandas as pd
def plot_mutation_with_sliders():
# 1. Read the CSV file
try:
data = pd.read_csv("time_data_multiprocessing.csv")
except FileNotFoundError:
print("Error: 'time_data_multiprocessing.csv' not found.")
return
mutation_rates = data["Mutation Rate"]
avg_generations = data["Average Time"]
# 2. Setup the Figure and Subplots
# We need space on the bottom and left for sliders, so we adjust the subplot
fig, ax = plt.subplots(figsize=(10, 7))
plt.subplots_adjust(bottom=0.25, left=0.15)
# 3. Initial Plot
# We store the 'line' object so we could update data later if needed (optional here)
line, = ax.plot(mutation_rates, avg_generations, marker='o', linestyle='-', color='b')
# Set initial titles and labels
ax.set_title("Impact of Mutation Rate on Convergence Speed")
ax.set_xlabel("Mutation Rate")
ax.set_ylabel("Generations")
ax.grid(True, linestyle='--', alpha=0.7)
# Calculate initial max values for limits
max_x = max(mutation_rates)
max_y = max(avg_generations)
# Set initial view
ax.set_xlim(0, max_x)
ax.set_ylim(0, max_y)
# 4. Create Sliders
# Define the area for the sliders [left, bottom, width, height]
ax_slider_x = plt.axes([0.15, 0.1, 0.65, 0.03], facecolor='lightgoldenrodyellow')
ax_slider_y = plt.axes([0.05, 0.25, 0.03, 0.6], facecolor='lightgoldenrodyellow')
# Create the slider objects
# valmin=0.01 prevents crashing by trying to zoom into 0 width
slider_x = Slider(ax_slider_x, 'Max X-Axis', valmin=0.01, valmax=1.0, valinit=max_x)
# Vertical slider for Y-axis (orientation='vertical')
slider_y = Slider(ax_slider_y, 'Max Y-Axis', valmin=10, valmax=max_y, valinit=max_y, orientation='vertical')
# 5. The Update Function
# This runs every time you move a slider
def update(val):
# Update the view limits based on slider values
ax.set_xlim(0, slider_x.val)
ax.set_ylim(0, slider_y.val)
# Redraw the figure
fig.canvas.draw_idle()
# Connect the sliders to the update function
slider_x.on_changed(update)
slider_y.on_changed(update)
print("Displaying interactive plot...")
plt.show()
if __name__ == "__main__":
=======
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
import pandas as pd
def plot_mutation_with_sliders():
# 1. Read the CSV file
try:
data = pd.read_csv("time_data_multiprocessing.csv")
except FileNotFoundError:
print("Error: 'time_data_multiprocessing.csv' not found.")
return
mutation_rates = data["Mutation Rate"]
avg_generations = data["Average Time"]
# 2. Setup the Figure and Subplots
# We need space on the bottom and left for sliders, so we adjust the subplot
fig, ax = plt.subplots(figsize=(10, 7))
plt.subplots_adjust(bottom=0.25, left=0.15)
# 3. Initial Plot
# We store the 'line' object so we could update data later if needed (optional here)
line, = ax.plot(mutation_rates, avg_generations, marker='o', linestyle='-', color='b')
# Set initial titles and labels
ax.set_title("Impact of Mutation Rate on Convergence Speed")
ax.set_xlabel("Mutation Rate")
ax.set_ylabel("Generations")
ax.grid(True, linestyle='--', alpha=0.7)
# Calculate initial max values for limits
max_x = max(mutation_rates)
max_y = max(avg_generations)
# Set initial view
ax.set_xlim(0, max_x)
ax.set_ylim(0, max_y)
# 4. Create Sliders
# Define the area for the sliders [left, bottom, width, height]
ax_slider_x = plt.axes([0.15, 0.1, 0.65, 0.03], facecolor='lightgoldenrodyellow')
ax_slider_y = plt.axes([0.05, 0.25, 0.03, 0.6], facecolor='lightgoldenrodyellow')
# Create the slider objects
# valmin=0.01 prevents crashing by trying to zoom into 0 width
slider_x = Slider(ax_slider_x, 'Max X-Axis', valmin=0.01, valmax=1.0, valinit=max_x)
# Vertical slider for Y-axis (orientation='vertical')
slider_y = Slider(ax_slider_y, 'Max Y-Axis', valmin=10, valmax=max_y, valinit=max_y, orientation='vertical')
# 5. The Update Function
# This runs every time you move a slider
def update(val):
# Update the view limits based on slider values
ax.set_xlim(0, slider_x.val)
ax.set_ylim(0, slider_y.val)
# Redraw the figure
fig.canvas.draw_idle()
# Connect the sliders to the update function
slider_x.on_changed(update)
slider_y.on_changed(update)
print("Displaying interactive plot...")
plt.show()
if __name__ == "__main__":
>>>>>>> 61c30840d841667855d5aadac32653688844cec0
plot_mutation_with_sliders()