简体   繁体   中英

Updateing multi-plot matplotlib

I have a problem witch updateing matplotlib chart. The problem is that i have many curve's on it, and after update the number of them may change. In example code I have 2 sets of data, 1st with 90 curves, and 2nd with 80, and i wish I could plot 1st set, and then 2nd, in the same matplotlib window.

import matplotlib.pyplot as plt
from matplotlib.transforms import Bbox
import numpy as np
from numpy.lib.polynomial import RankWarning
import pandas as pd
import sys

fig, ax = plt.subplots()
fig.subplots_adjust(right=0.78)
_x = []
_y = []
_y1 = []
_x1 = []
for x in range(90):
    _x.append(np.linspace(0, 10*np.pi, 100))
    _y.append(np.sin(_x[x])+x)
for x in range(80):
    _x1.append(np.linspace(0, 10*np.pi, 150))
    _y1.append(np.tan(_x1[x]+x))


def narysuj(__x, __y):

    p = []  # p-pomiar
    f = []  # f-czestotliwosc
    for x in range(len(__x)):
        p.append([])
        f.append([])
    ax.set_prop_cycle(color=plt.cm.gist_rainbow(np.linspace(0, 1, len(__x))))
    for x in range(len(__x)):
        for line in range(len(__x[x])):
            #print(len(_y[x]), line)
            p[x].append(__y[x][line])
            f[x].append(__x[x][line])
        ax.plot(f[x], p[x], label=f"Label {x}")
    plt.show()


narysuj(_x, _y)
narysuj(_x1, _y1)

PS I know the way I'm drawing those charts is highly ineffective.

I found what was the problem. I had to add plt.ion() at the start of program and ax.clear() before drawing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM