On Tuesday, 17 May 2016 09:17:16 UTC+1, steve...@metoffice.gov.uk wrote:
> On Monday, 16 May 2016 16:29:52 UTC+1, alx wrote:
>> Le lundi 16 mai 2016 14:30:56 UTC+2, steve...@metoffice.gov.uk a écrit :
>>> On Monday, 16 May 2016 13:07:13 UTC+1, steve...@metoffice.gov.uk wrote:
>>>> On Monday, 16 May 2016 12:26:47 UTC+1, Steve wrote:
>>>> > Hi
>>>> >
>>>> > I am having trouble labeling a time axis on an image. Here is some test code
>>>> >
>>>> > ;create a randomn image for testing
>>>> > data = RANDOMU(seed,1800,401)
>>>> > img = BYTSCL(data)
>>>> >
>>>> > ;data values that I would like to use for labeling the axes
>>>> > xval = FINDGEN(1800)/(60.*60.*24.) + JULDAY(11,24,2014,11,15,00)
>>>> > yval = FINDGEN(401)-200.
>>>> >
>>>> > ;plot the image and label the axes
>>>> > im = IMAGE(img, RGB_TABLE=0,MARGIN=0.2)
>>>> > yax = AXIS('Y', LOCATION=[0,0], TICKDIR=1, MINOR=0, COORD_TRANSFORM=[yval[0],1])
>>>> > xax = AXIS('X', LOCATION=[0,0], TICKDIR=1, MINOR=0, TICKFORMAT='(C(CHI2.2, ":", CMI2.2))', COORD_TRANSFORM=[xval[0],1.])
>>>> >
>>>> > I am using COORD_TRANSFORM in the call to AXIS to try and convert the pixel number of the image to what I would like to display. In the example above this works for the yaxis which simply changes the axis data values. For the xaxis I am also trying to display it in a time format as HH:MM but all of the axes labels display as 00:00.
>>>> >
>>>> > Any idea how I can label the xaxis correctly?
>>>> >
>>>> > Thanks
>>>> >
>>>> > Steve
>>>>
>>>> Just spotted an error in my test code. The xaxis should be
>>>>
>>>> xax = AXIS('X', LOCATION=[0,0], TICKDIR=1, MINOR=0, TICKFORMAT='(C(CHI2.2, ":", CMI2.2))', COORD_TRANSFORM=[xval[0],1./(60.*60.*24.)])
>>>>
>>>> This does put what look to be about the correct times but they all overlay each other on the axis. Something is not quite right!
>>>>
>>>> Steve
>>>
>>> OK so a little more playing around with this and I guess the problem may be due to COORD_TRANSFORM not using double precision, such that when it displays the time values on the xaxis they end up overlaying each other. Perhaps someone can confirm.
>>>
>>> So a big fudge to get this to work is to change
>>>
>>> xval = FINDGEN(1800)/(60.*60.*24.) + JULDAY(11,24,-4712,11,15,00)
>>>
>>> such that the data values put into COORD_TRANSFORM are not as large. Clearly I wouldn't be able to display the time axis with the year labeled in this case.
>>>
>>> If anyone has a better solution to the above that would be great.
>>>
>>> Steve
>>
>> Don't use your axis trick.
>> Simply use the IMAGE function with AXIS_STYLE=2 and ASPECT_RATIO=0. The IMAGE_DIMENSIONS and IMAGE_LOCATION keywords will directly set the correct axes.
>> alx.
>
> Thanks alx. That works!
For completeness the working test case is
;create a randomn image
data = RANDOMU(seed,1800,401)
img = BYTSCL(data)
;values I would like to use for labeling the axes
xval = FINDGEN(1800)/(60.*60.*24.) + JULDAY(11,24,2014,11,15,00)
yval = FINDGEN(401)-200.
im = IMAGE(img, RGB_TABLE=0, MARGIN=0.2, AXIS_STYLE=2, ASPECT_RATIO=0, $
IMAGE_LOCATION = [xval[0],yval[0]], $
IMAGE_DIMENSIONS = [MAX(xval)-MIN(xval),MAX(yval)-MIN(yval)],$
XTICKFORMAT='(C(CHI2.2, ":", CMI2.2))', XTICKDIR=1, YTICKDIR=1)
ax = im.AXES
ax[2].ticklen=0.
ax[3].ticklen=0.
Steve
|