Python 如何同时绘制多个大型数据集?

Python 如何同时绘制多个大型数据集?,python,matplotlib,concurrency,data-science,data-visualization,Python,Matplotlib,Concurrency,Data Science,Data Visualization,我正在用python绘制多个大型数据集。由于图形的数量以及生成每个图形所需的时间,我一直在玩并行运行图形功能的游戏 为了绘制图表,我混合使用了matplotlib和seaborn,为了处理多处理,我使用了ThreadPoolExecutor库。除了图形的一些并发性问题外,它在大多数情况下都可以正常工作。似乎有某种共享资源正在导致图形显示方式出现一些非常意外的结果,例如缺少图形、出现额外的线条以及x轴未对齐 在这一点上,我甚至不确定是否有可能在并行图形数据了,所以这就是为什么我在这里寻求建议。 我

我正在用python绘制多个大型数据集。由于图形的数量以及生成每个图形所需的时间,我一直在玩并行运行图形功能的游戏

为了绘制图表,我混合使用了matplotlib和seaborn,为了处理多处理,我使用了ThreadPoolExecutor库。除了图形的一些并发性问题外,它在大多数情况下都可以正常工作。似乎有某种共享资源正在导致图形显示方式出现一些非常意外的结果,例如缺少图形、出现额外的线条以及x轴未对齐

在这一点上,我甚至不确定是否有可能在并行图形数据了,所以这就是为什么我在这里寻求建议。 我想知道其他人会如何安排多个大型绘图过程

下面是我正在做的一个淡化的例子:

from concurrent import futures
from concurrent import ThreadPoolExecutor, wait, ALL_COMPLETED
import pandas as pd
import numpy

def testjob(ReportsToBeCharted):
    # ReportsToBeCharted is a dictionary(<string, Dataframe> )
    with ThreadPoolExecutor(3) as executor:
         jobs = []
         results_done = []
         for reportName, Report in ReportsToBeCharted.items():
         # pass each report to its own specified charting method based on its key name
             if reportName == "Report 1":
                print("Report 1 job start")
                jobs.append(executor.submit(chartReport1,Report))
                continue
             if reportName == "Report 2":
                print("Report 2 job start")
                jobs.append(executor.submit(chartReport2,Report))
                continue
             if reportName == "Report 3":
                print("Report 2 job start")
                jobs.append(executor.submit(chartReport3,Report))
                continue
    orderedResults = [r.result() for r in jobs]


def chartReport1(report):
    #
    #Additional data formatting code here
    #ChartReport2 and charReport3 will have similar behavior
    #
    chartStaircase(report, lim1,lim2,lim3,title)


def chartStaircase(report,lim1,lim2,lim3,title):
    import seaborn as sea
    import matplotlib.pyplot as plot
    #I tried importing these libraries inside this function so that each job has it's own instance to 
    # use?
    ASPECT_Ration = 2

    sea.set(style = "ticks")
    sea.set_context("talk")
    fig,ax = plot.subplots(figsize = plot.figaspect(ASPECT_RATIO))
    sea.lineplot(x = "latency", y = "Percentile", data = report, sort = False)
    ax.axvspan(lim1,lim3, facecolor = 'r', alpha=.5)
    sea.despone(trim=True,left=True)
    ax.axhspan(lim2,lim3, facecolor = "black")
    fig.subtitle("subtitle")
    ax.set(ylabel = "yLabel")
    ax.set(xlabel = "xlabel")
    plot.savefig("figure.png")
来自并发导入的

从并发导入ThreadPoolExecutor,等待,所有_完成
作为pd进口熊猫
进口numpy
def testjob(报告已归档):
#ReportsToBeCharted是一本字典()
使用ThreadPoolExecutor(3)作为执行器:
工作=[]
结果_done=[]
对于reportName,在ReportsToBeCharted.items()中报告:
#根据每个报表的键名将其传递给自己指定的图表方法
如果reportName==“报告1”:
打印(“报告1作业开始”)
jobs.append(executor.submit(chartReport1,Report))
持续
如果reportName==“报告2”:
打印(“报告2作业开始”)
jobs.append(executor.submit(chartReport2,Report))
持续
如果reportName==“报告3”:
打印(“报告2作业开始”)
jobs.append(executor.submit(chartReport3,Report))
持续
orderedResults=[r.result()用于作业中的r]
def chartReport1(报告):
#
#这里有其他数据格式代码
#ChartReport2和charReport3将具有类似的行为
#
图表楼梯(报告,lim1,lim2,lim3,标题)
def图表(报告,lim1,lim2,lim3,标题):
进口海运
将matplotlib.pyplot导入为绘图
#我尝试在这个函数中导入这些库,这样每个作业都有它自己的实例
#使用?
纵横比=2
sea.set(style=“ticks”)
sea.设置上下文(“对话”)
图,ax=绘图子图(figsize=绘图子图(纵横比))
sea.lineplot(x=“延迟”,y=“百分位”,数据=报告,排序=假)
ax.axvspan(lim1,lim3,facecolor='r',alpha=.5)
sea.despone(修剪=真,左=真)
ax.axhspan(lim2、lim3、facecolor=“黑色”)
图副标题(“副标题”)
ax.set(ylabel=“ylabel”)
ax.set(xlabel=“xlabel”)
plot.savefig(“figure.png”)