Created
January 25, 2025 00:43
-
-
Save sparrowDom/6ad191ff59703eaa61c684ba67191c37 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # import matplotlib.animation | |
| import matplotlib.pyplot as plt | |
| from matplotlib.patches import Rectangle | |
| import numpy as np | |
| import json | |
| plt.rcParams["animation.html"] = "jshtml" | |
| plt.rcParams['figure.dpi'] = 150 | |
| plt.ioff() | |
| fig, ax = plt.subplots() | |
| with open('ichiVault_27SnapshotTimeline.json', 'r') as file: | |
| data = json.load(file) | |
| numpy_array = np.array(data) | |
| dataLength = len(numpy_array) | |
| x= np.linspace(-30,30,60) | |
| # Arbitrary decision: totalAmount of 2 positions 10 ticks wide is tall 10 units | |
| def printLiquidity(lowerTick, upperTick, totalPositionAmount, totalAmounts, color): | |
| width = (upperTick - lowerTick) | |
| if (width == 0): | |
| return | |
| amountPerSquareUnit = totalAmounts / 100 # 10 ticks wide and 10 units tall | |
| height = totalPositionAmount / width / amountPerSquareUnit | |
| height = height if height > 0.2 else 0.2 | |
| ax.add_patch(Rectangle((lowerTick, 0), width, height, facecolor = color)) | |
| def animate(t): | |
| data = numpy_array[t] | |
| plt.cla() | |
| printLiquidity(int(data['baseLower']), int(data['baseUpper']), int(data['totalBaseAmount']), int(data['totalAmounts']), 'lightsteelblue') | |
| printLiquidity(int(data['limitLower']), int(data['limitUpper']), int(data['totalLimitAmount']), int(data['totalAmounts']), 'cornflowerblue') | |
| plt.plot() | |
| plt.xlim(-30,30) | |
| plt.ylim(0,10) | |
| matplotlib.animation.FuncAnimation(fig, animate, frames=dataLength) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment