|
From: KURT P. <pet...@ms...> - 2013-10-01 17:55:09
|
> Date: Tue, 1 Oct 2013 19:35:39 +0200
> Subject: Re: [Matplotlib-users] x axis non-uniform labeling (KURT PETERS)
> From: goy...@gm...
> To: pet...@ms...
> CC: pmh...@gm...; mat...@li...
>
> 2013/10/1 KURT PETERS <pet...@ms...>:
> > here's what SHOULD be happening
> >
> > | 0 1 5 9 13 18 21 24 25 28
> > 3 | x
> > | x x
> > | x x
> > | x x
> > -1|_x__________________x_____
> > 1 2 3 4 5 6 7 8 9 10
> >
> > How can I make that happen? Instead, MPL is autoranging the top axis. I
> > don't want that I just want the actual labels to occur up there.
>
> Then just set the ticks and the tick labels of the axis:
>
> import numpy as np
> import matplotlib.pyplot as plt
> xdat=np.arange(1,11)
> simtimedata = np.array([0, 1, 5, 9, 13, 18, 21, 24, 25, 28])
> idatanp = np.array([-1,0, 1, 2, 3, 2, 1, 0, -1, -2])
> ax1 = plt.subplot(111)
> ax1.plot(xdat,idatanp)
> ax2 = ax1.twiny()
> ax2.set_xticks(range(len(xdat)))
> ax2.set_xticklabels(simtimedata)
> plt.show()
>
> Goyo
Goyo, Thanks, the code below seems to work. The problem is that with "REAL/actual" data, I have SO many data points that each point is now labeled and it takes forever to render. And when it does render, I cannot read the axis because there are too many there. Is there a way to judiciously have it only display a certain number of values? Such as every 100th value?Kurtxdat=np.arange(1,11)
simtimedata = np.array([0, 1, 5, 9, 13, 18, 21, 24, 25, 28])
idatanp = np.array([-1,0, 1, 2, 3, 2, 1, 0, -1, -2])
print idatanp.shape
print simtimedata.shape
print xdat.shape
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax1.plot(xdat,idatanp)
ax1.grid(True)
ax2 = fig.add_subplot(212)
ax2.plot(xdat, idatanp.real,'k-o')
ax2.set_xticks(xdat)
ax2.set_xticklabels(simtimedata)
#ax2.set_title("time domain")
ax2.grid(True)
plt.show() |