-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the graph for better visualization (#23)
* Change the graph for better visualization * Changed the graph --------- Co-authored-by: Tanisha Lalwani <[email protected]>
- Loading branch information
1 parent
9de5f2c
commit ca02b23
Showing
1 changed file
with
32 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import time | ||
import random | ||
|
||
xdata = [] | ||
ydata = [] | ||
|
||
|
||
# Initialize the figure | ||
plt.figure() | ||
|
||
# Set up the axes | ||
plt.axis("off") # Turn off the axis for a cleaner look | ||
|
||
# Create an empty grid for the heatmap | ||
heatmap_data = np.zeros((10, 10)) # 10x10 grid | ||
|
||
# Show the plot window | ||
plt.ion() # Turn on interactive mode | ||
plt.show() | ||
|
||
axes = plt.gca() | ||
axes.set_xlim(0, 100) | ||
axes.set_ylim(0,1) | ||
line, = axes.plot(xdata, ydata, 'r-') | ||
|
||
|
||
# Loop to simulate data for the heatmap | ||
for i in range(100): | ||
xdata.append(i) | ||
ydata.append(i/2) | ||
line.set_xdata(xdata) | ||
line.set_ydata(ydata) | ||
# Randomly generate data (for example purposes) | ||
data = np.random.rand(10, 10) # Random values between 0 and 1 for a 10x10 grid | ||
heatmap_data += data # Accumulate data for the heatmap | ||
|
||
# Clear the axes and plot the heatmap | ||
plt.clf() # Clear the current figure | ||
heatmap = plt.imshow( | ||
heatmap_data, cmap="hot", interpolation="nearest", vmin=0, vmax=100 | ||
) # Create heatmap | ||
plt.colorbar(heatmap) # Add a colorbar to indicate scale | ||
plt.title("Dynamic Heatmap of Random Values") | ||
|
||
# Update the plot | ||
plt.draw() | ||
plt.pause(1e-17) | ||
|
||
# add this if you don't want the window to disappear at the end | ||
plt.pause(0.5) # Pause to see the update | ||
|
||
# Keep the plot window open at the end | ||
plt.ioff() # Turn off interactive mode | ||
plt.show() |