【问题标题】:Applying dask dataframe to 3D bar chart将 dask 数据框应用于 3D 条形图
【发布时间】:2021-08-11 18:17:01
【问题描述】:

我正在尝试使用 matplotlib 将 dask 数据帧从 30gb csv 文件加载到 3D 条形图中。

问题是任务已经运行了好几天,但一旦到达代码的“颜色设置”部分,就看不到尽头。

我试图让它只使用数据框中有限数量的行,但 dask 似乎不允许行索引,只允许列索引。

所以我拆分分区并使用分区大小来限制行大小。 然而,即使只有 100 行,也需要几天时间。

我怀疑计算 100 行颜色设置需要几天时间(甚至还没有到绘图部分)

很明显我做错了什么。

这是数据框的样子

这里是代码

   %matplotlib inline
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
from matplotlib import cm
import pandas as pd
# import ipynb.fs.full.EURUSD
from colorspacious import cspace_converter
from collections import OrderedDict
import numpy as np
import os
import dask
import dask.array as da
import dask.dataframe as dd
from dask.diagnostics import ProgressBar
from memory_profiler import memory_usage
import memory_profiler
%load_ext memory_profiler
cmaps = OrderedDict()


df = dd.read_csv(r'G:\Forex stuff\ticks2\Forex\EURUSD_mt5_ticks.csv')

npart = round(len(df)/1000)
parted_df = df.repartition(npartitions=npart)

first_1000_rows = parted_df.partitions[0]

first_1000_rows.head(100)

ylist = df["Bid_Price"]
xlist = df["Date"]
zlist = df["Bid_Volume"]

xpos = xlist
ypos = ylist

num_elements = len(first_1000_rows)

zpos = np.zeros(num_elements)
dx = np.ones(num_elements)
dy = np.ones(num_elements)
dz = zlist

from dask.distributed import Client

client = Client("tcp://10.0.0.98:8786")
client.cluster

#color settings
cmap = cm.get_cmap('Spectral') # Get desired colormap - you can change this!
max_height = np.max(dz)   # get range of colorbars so we can normalize
min_height = np.min(dz)
#scale each z to [0,1], and get their rgb values
rgba = [cmap((k-min_height)/max_height) for k in dz] 


fig = plt.figure(figsize=(20, 20))
ax1 = fig.add_subplot(111, projection='3d')
ax1.bar3d(xpos, ypos, zpos, dx, dy, dz, color=rgba, zsort='average')
plt.show()

我经常在运行过程中遇到超时和不稳定错误。但是 dask GUI 告诉我它正在工作。但是我显然不是只运行 100 行,因为它需要很长时间。

我很确定它只是一遍又一遍地循环相同的任务,因为 dask 在 GUI 内的每个循环结束时都会从 ram 中转储 10 gigs 的集群数据,然后重置。

有什么想法可以改进吗? 赞赏。

【问题讨论】:

标签: python csv matplotlib dask


【解决方案1】:

这些行使用原始的df,您可以检查这些列表的大小:

ylist = df["Bid_Price"]
xlist = df["Date"]
zlist = df["Bid_Volume"]

你想要这个:

ylist = parted_df["Bid_Price"]
xlist = parted_df["Date"]
zlist = parted_df["Bid_Volume"]

【讨论】:

  • 嗯。也许你是对的。我曾假设 num_elements 会为我拆分它。我花了很多时间寻找行索引的语法,我从未考虑过这种可能性。我会试试看,现在让你:)
  • 我不知道它到底做了什么,但根据 GUI 告诉我的内容,完成它的过程可能需要一个月的时间。回到我认为的绘图板?
猜你喜欢
  • 2020-11-10
  • 1970-01-01
  • 1970-01-01
  • 2017-11-10
  • 2017-10-24
  • 2015-01-03
  • 1970-01-01
  • 2021-07-29
相关资源
最近更新 更多