Python 多个子批次的线程化matplotlib

Python 多个子批次的线程化matplotlib,python,multithreading,matplotlib,Python,Multithreading,Matplotlib,我从未使用过线程,我想知道是否可以为matplotlib执行线程打印。当matplotlib有一个较大的数据集时,生成图形的速度会非常慢。我尝试编写代码来执行下面的过程,但它确实显示了一个图形 from pylab import * import threading import pandas as pd import numpy as np import matplotlib.pyplot as plt def gp1(aa): fig=plt.figure() ax1=pl

我从未使用过线程,我想知道是否可以为matplotlib执行线程打印。当matplotlib有一个较大的数据集时,生成图形的速度会非常慢。我尝试编写代码来执行下面的过程,但它确实显示了一个图形

from pylab import *
import threading
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

def gp1(aa):
    fig=plt.figure()
    ax1=plt.subplot2grid((3,3), (0,0), colspan=3)
    aa['a'].hist(color='g')
    aa['b'].hist(color='b')
def gp2 (bb):
    ax2=plt.subplot2grid((3,3), (1,0), colspan=3)
    bb['c'].hist(color='r')
    bb['d'].hist(color='y')

def gp3(cc):
    ax3=plt.subplot2grid((3,3), (2,0), colspan=3)
    cc['a'].hist(color='b')
    cc['c'].hist(color='r')



def graph(aa):
    a = threading.Thread(target=gp1, args=aa)
    b = threading.Thread(target=gp2, args=aa)
    c = threading.Thread(target=gp3, args=aa)

    a.start()
    b.start()
    c.start()
    plt.show()


df = pd.DataFrame(randn(1000, 4), columns=['a', 'b', 'c', 'd'])

graph(df)

我想问的几个问题是,这会使绘图更快吗?通过展示stackoverflow和其他示例,是否有一个学习线程的好地方?

一般来说,后端对线程的使用不是很好。这是可以做到的(我认为,但可能需要英勇的编码),但可能不值得这么麻烦。你分析过你的代码吗?你确定mpl是瓶颈吗?您正在使用图形/轴吗?有一大堆低挂果实,可以帮助不需要复杂的线程。@tcaswell我从来没有使用过线程或多处理之前,只是想知道如何正确地使用它的代码。