Answers for "interactive graph matplotlib"

20

how to plot a graph using matplotlib

from matplotlib import pyplot as plt
plt.plot([0, 1, 2, 3, 4, 5], [0, 1, 4, 9, 16, 25])
plt.show()
Posted by: Guest on February-10-2020
0

matplotlib plot interactive

# Note: plot will be frozen when running with python console
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use("TkAgg")
import numpy as np

x = np.linspace(0, 6*np.pi, 100)
y = np.sin(x)

plt.ion()

fig = plt.figure()
ax = fig.add_subplot(111)
line1, = ax.plot(x, y, 'r-')
plt.draw()  # the line can be deleted

for phase in np.linspace(0, 10*np.pi, 500):
    line1.set_ydata(np.sin(x + phase))
    plt.draw()
    plt.pause(0.02)

plt.ioff()
plt.show()
Posted by: Guest on December-02-2020

Python Answers by Framework

Browse Popular Code Answers by Language