Uncategorized

matplotlib – The legend of the animation plot is overlap in python


I am trying to generate Random pressures and interpolate them into a 2D graph. But when I run the below code,enter image description here it gives an overlapped legend in the plot. How to solve this problem?

def animate(i):
current_pressure = generate_random_pressures()
interpolated_pressure = griddata((nodes_x, nodes_y), current_pressure, (grid_x, grid_y), method='nearest')
plt.scatter(nodes_x, nodes_y, c=current_pressure, marker="o", cmap='viridis', label="Nodes")
plt.contourf(grid_x, grid_y, interpolated_pressure, cmap='viridis', alpha=0.5)
plt.title('Pressure Interpolation on 2D Surface')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.colorbar(label="Pressure")
cbb=plt.legend()
cbb.remove()
cb = plt.colorbar()
cb.remove()
ani= FuncAnimation(plt.gcf(), animate, interval=1000, frames=5, repeat=False)
plt.show()



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *