Search code examples
pythonmatplotlibaxesimshow

Plot an imshow graph with axes limits beyond the end of the data sets


I have a 2d matrix which corresponds to time (columns) and height (rows). I've managed to get it to plot using imshow just fine (with time on the x axis and height on the y axis), however I will be plotting a number of days, some of which will not have 24hrs worth of data. For the days with less than 24hrs of data, I would still like them to plot on a 24hr time axis with the data plotting starting from their start time on the x axis.

I have tried plotting this on pcolormesh which didn't resolve the problem, and also to plot a plt.plot over the top with all the time values and height values of nan.

I also tried changing the extent to a time base, based off 24/(the difference in time steps), but that didn't have an affect either. Below is the code I am using as well as a sample data set to show the format of my data;

time = [0.01649999991059303, 0.02584999985992908]
rdata = [-600.020751953125, -570.04150390625, -540.062255859375, -510.0830078125, -480.1037902832031, -450.1245422363281, -420.1452941894531, -390.1660461425781, -360.1867980957031, -330.2075500488281]
intensity = [[-37.32464981079102, -38.3233528137207], [-37.70231628417969, -38.05134201049805], [-38.27889251708984, -38.82979583740234], [-28.01022720336914, -27.68825912475586], [-8.408446311950684, -8.440451622009277], [-8.749446868896484, -8.750232696533203], [-9.431790351867676, -9.41820240020752], [-10.09048461914062, -10.23848724365234], [-10.84317588806152, -10.84869194030762], [-11.61933135986328, -11.67543029785156]]

t_start = time[0]
t_end = time[-1]
r_start = rdata[0]
r_end = rdata[-1]

fig = plt.figure(figsize=[8,5])
X,Y = meshgrid(time,rdata)
#plt.pcolormesh(X,Y, intensity, norm=None)
plt.imshow(intensity,aspect='auto',origin='lower',extent=[t_start,t_end,r_start,r_end])
plt.colorbar()
plt.show()

Any help with this would be greatly appreciated!


Solution

  • can't you simply change the range of X values shown on the x-axis?

    plt.xlim([0,0.035])
    

    enter image description here