Python 使用matplotlib创建每周时间表

Python 使用matplotlib创建每周时间表,python,numpy,matplotlib,Python,Numpy,Matplotlib,编辑:我将数据类型更改为Pandas DataFrame,看起来像这样(datetime.datetime,int),以便使问题更简单 原职: 我有一个数据报告的numpy数组,看起来像这样(datetime.datetime,int,int),我似乎无法正确地绘制它。我需要X轴是一个24小时的阵列 np.array([datetime.datetime.time(x) for x in DataArr]) Y应该是datetime之后的天(星期一、星期二等) int应该为不同的事件提供不同的

编辑:我将数据类型更改为Pandas DataFrame,看起来像这样
(datetime.datetime,int)
,以便使问题更简单

原职:

我有一个数据报告的numpy数组,看起来像这样
(datetime.datetime,int,int)
,我似乎无法正确地绘制它。我需要X轴是一个24小时的阵列

np.array([datetime.datetime.time(x) for x in DataArr])
Y应该是datetime之后的天(星期一、星期二等) int应该为不同的事件提供不同的颜色,但是我找不到一个例子 在matplotlib的网站上

我正在寻找的一个例子:


听起来你想要这样的东西

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

# I'm using pandas here just to easily create a series of dates.
time = pd.date_range('01/01/2013', '05/20/2013', freq='2H')
z = np.random.random(time.size)

# There are other ways to do this, but we'll exploit how matplotlib internally
# handles dates. They're floats where a difference of 1.0 corresponds to 1 day.
# Therefore, modulo 1 results in the time of day. The +1000 yields a valid date.
t = mdates.date2num(time) % 1 + 1000

# Pandas makes getting the day of the week trivial...
day = time.dayofweek

fig, ax = plt.subplots()
scat = ax.scatter(t, day, c=z, s=100, edgecolor='none')
ax.xaxis_date()

ax.set(yticks=range(7),
       yticklabels=['Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun'])

# Optional formatting tweaks
ax.xaxis.set_major_formatter(mdates.DateFormatter('%l%p'))
ax.margins(0.05)
fig.colorbar(scat)
plt.show()

你想要绘制什么样的实际绘图?活动文档-请参阅linked photo@omryjs我已将你的图片添加到内联中,一旦你有足够的声誉,你就可以自己绘制。我正在尝试运行你的代码,但我得到“AttributeError:'module'对象没有属性'子绘图'”错误。对于线“fig,ax=plt.subplot()我的matplotlib.\uuuu版本\uuuuu=='1.2.1'我已经更新了我的库,但不幸的是,我无法从您提供的代码中获得绘图-我基本上就是我要寻找的。请查看我上面链接的照片,但我正在尝试获得类似的内容this@omryjs您是如何更新matplotlib的?如果是手动更新的,是否在安装之前删除了旧版本新?@FrancescoMontesano I使用matplotlib网站上的.exe文件进行更新。