Hello,
I am trying to make a simple pcolor plot with a datetime on the x-axis. I am able to get a time label on the x-axis fine with a regular plot command, but it doesn’t appear to work if you use pcolor. This simple example below shows that it does not work. Does anyone have any idea as to why a datetime can’t go on a pcolor plot? What is the best approach is to solve the problem?
Thanks,
Tim
import numpy as np
import datetime
import random
import matplotlib
import matplotlib.pyplot as plt
create some random data, one for a line plot, and another for pcolor:
data1 = np.array ([random.random() for k in range(10)])
data2 = np.zeros((10,10))
for i in range(10):
for j in range(10):
data2[i,j] = random.random()
build datetimes (dts):
dts = []
for k in range(10):
dts.append(datetime.datetime(2012,1,1+k))
First example, showing a regular plot with datetimes in the x-axis.
fig = plt.figure(1)
fig.clf()
ax = fig.add_subplot(111)
ax.plot(dts,data1)
plt.show()
Second example, showing a pcolor with datetimes in the x-axis.
This plot does not work.
fig = plt.figure(2)
fig.clf()
ax = fig.add_subplot(111)
ax.pcolor(dts,np.arange(10),data2)
plt.show()
It doesn’t work because we probably never had a request for it and therefore never tested that case. Testing it out with v1.1.1-rc2 shows that for pcolor(), first of all, it expects a numpy array for the input arrays (that should definitely be fixed) as opposed to a python array. Second, fixing that, there is an issue where the Path object in the pcolor object is expecting floating points for its vertices. If one uses pcolormesh instead, right off the bat, there is a problem where it attempts to make a 2-D version of the 1-D input array, but because the 2-D array was created with default dtype, it is expecting something compatible with a float type. Personally, I am not liking how pcolormesh is being inefficient with my input arrays and it should really be taking advantage of numpy broadcasting.
Could you please file a bug report on github for this issue with your code example?
Thanks!
Ben Root
···
On Wed, Jun 13, 2012 at 4:00 PM, Timothy Duly <timduly4@…287…> wrote:
Hello,
I am trying to make a simple pcolor plot with a datetime on the x-axis. I am able to get a time label on the x-axis fine with a regular plot command, but it doesn’t appear to work if you use pcolor. This simple example below shows that it does not work. Does anyone have any idea as to why a datetime can’t go on a pcolor plot? What is the best approach is to solve the problem?
Thanks,
Tim