[ncl-talk] Scaling overlapping markers using xyMarkerSizes does not work

Adam Phillips asphilli at ucar.edu
Wed Nov 7 15:41:07 MST 2018


Hi Brandon,
Thank you for sending an easy to run script that illustrates the issue you
are having. To answer your question about why xyMarkerColors/xyMarkerSizes
are not working as you expected: It's not intuitive, but those resources
work for all instances of y for every instance of x in the input array. For
example, if you your code is like this:
; y is a 1D array of same size as x
res at xyMonoMarkerSize = False
res at xyMarkerSizes = (/3,5,6/)
plot = gsn_csm_xy(wks,x,y,res)

all points shown in the plot will be using marker 3. However, if y is a 2D
array dimensioned 3 x dimsizes(x), then the first line of y (0,:) will be
drawn with marker 3, the second line of y (1,:) will be drawn with marker
5, and the third line of y (2,:) will be drawn with marker 6.

To answer your second question about the lines, it's likely best to just
draw a blank plot.
Replace this:
plot = gsn_csm_xy(wks,x,cdata,res)
with this:
plot = gsn_csm_blank_plot(wks,res)
Adam

On Wed, Nov 7, 2018 at 12:51 PM Brandon Fisel <bjfisel at gmail.com> wrote:

> I have updated the code to use gsn_add_polymarker, which now appropriately
> scales the marker sizes. However, there are now annoying lines connecting
> (at random) some of the hollow circles. I would like to remove these lines.
>
> Below is the code I added. Remove the last do loop that plots the data,
> and insert the following between x = ispan(1,dmax,1) and frame(wks):
>
>   res at xyMarkerColor = "white"
>   plot = gsn_csm_xy(wks,x,cdata,res)
>   mkres = True
>   dum_fill = new((/nset,dmax/),graphic)
>   do i=0,nset-1
>     do j=0,dmax-1
>       mkres at gsMarkerIndex = markers(i)
>       mkres at gsMarkerSizeF = marker_size(i,j)
>       mkres at gsMarkerColor = colors(i,:)
> ;      plot@$unique_string("dum")$ =
> gsn_add_polymarker(wks,plot,x(j),cdata(i,j),mkres) ;works same as below
>       dum_fill(i,j) = gsn_add_polymarker(wks,plot,x(j),cdata(i,j),mkres)
>     end do
>   end do
>   draw(plot)
>
>
> On Wed, Nov 7, 2018 at 12:24 PM Brandon Fisel <bjfisel at gmail.com> wrote:
>
>> Hello,
>>
>> The below code is running on NCL version 6.4.
>>
>> I am attempting to adjust the marker sizes of hollow circles when they
>> overlap on an XY plot. The "marker_size" variable in the script, is the
>> algorithm that adjusts the marker sizes. Printing the marker_size output,
>> shows the algorithm works correctly, placing into an array the adjusted
>> marker sizes where the points will overlap.
>>
>> Unfortunately, the xyMarkerSizes is taking the first value in the array,
>> as the marker size for that set. The resource information mentions
>> xyMarkerSizes takes arrays for marker sizes, and that is not working.
>>
>> I have tested putting a static array of marker sizes, and that also does
>> not work. Further, I have tested creating my own markers using
>> NhlNewMarker, and this also is not working.
>>
>> How might I be able to adjust these marker sizes, so that if hollow
>> circles overlap they adjust in size, allowing you to see each point?
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>> ;*********************************************
>> begin
>> ; number of sets and values
>>   nset = 3
>>   nval = 30
>> ; generate random data
>>   random_setallseed(36484749, 9494848)
>>   lo = 0
>>   hi = 10
>>   data = tointeger(random_uniform(lo, hi, (/nset, nval/)))
>>   med_data = dim_median(data) ;median of data
>> ; persistent values > set median
>> ; output at last persistent value
>>   per_val = new((/nset,nval/),float,-999.)
>>   i = 1 ;persistence counter
>>   do k=0,nset-1 ;loop over each set
>>     i = 1 ;reset persistence counter
>>     do n=1,nval-1
>>       if (data(k,n-1).gt.med_data(k)) then ;first value
>>         if (data(k,n).gt.med_data(k)) then ;every value after first
>>           FLAG = True ;closure flag to check (and output persistence)
>> index at end of array
>>           i = i+1 ;iterate by 1
>>           if (n.eq.nval-1) then ;end of array check
>>             if (FLAG) then ;if at the end of array
>>               per_val(k,n) = i ;output index if persistence exists at end
>> of array
>>             end if
>>           end if
>>         else
>>           per_val(k,n-1) = i ;output index at end of persistent value
>>           i = 1 ;reset index to 1 when persistence ends
>>           FLAG = False ;disable closure flag (not at end of array yet)
>>         end if
>>       end if
>>     end do
>>   end do
>> ; largest bin (largest persistent period)
>>   dmax = tointeger(max(per_val)) ;needs to be scalar
>> ; bin persistent periods
>>   cdata = new((/nset, dmax/),"float",-999.)
>>   j_array = ispan(1,dmax,1)
>>   do i=0,nset-1
>>     do j=0,dmax-1
>>       cdata(i,j) = num(per_val(i,:).eq.j_array(j))
>>     end do
>>   end do
>> ; set 0 to FillValue
>> ; for determination of unique values (for markes
>>   cdata at _FillValue = 0.
>> ; set up plot
>>   wks = gsn_open_wks("pdf","example")
>>   cmap = read_colormap_file("cb_9step") ;color map for markers
>>   colors = cmap(38:40,:) ;3 colors centered about the middle of the cmap
>>   markers = (/4,4,4/) ;marker shapes (hollow circles)
>> ; rescale marker sizes where they overlap
>> ; increase scale by 0.002
>>   marker_size = new((/nset,nval/),"float")
>>   marker_size = 0.007 ;default marker size
>>   do i=0,dmax-1
>>     do j=1,nset-1
>>       marker_size(j,i) = marker_size(j,i) +
>> num(cdata(:j-1,i).eq.cdata(j,i))*0.002
>>     end do
>>   end do
>>   res = True
>>   res at gsnDraw = False
>>   res at gsnFrame = False
>>   res at tiMainString = "Example plot"
>>   res at xyMarkLineModes = "Markers"
>>   res at tiXAxisString = "Bins"
>>   res at tiYAxisString = "Frequency"
>>   res at trXMinF = 0
>>   res at trXMaxF = dmax+1
>>   res at trYMinF = 0
>>   res at trYMaxF = max(cdata)+1
>>   res at tmLabelAutoStride = True
>>   res at xyMonoMarker = False
>>   res at xyMonoMarkerColor = False
>>   res at xyMonoMarkerSize = False
>> ; loop over and plot each binned value
>>   x = ispan(1,dmax,1)
>>   do i=0,nset-1
>>     res at xyMarkers = markers(i)
>>     res at xyMarkerSizes = marker_size(i,:)
>> ;    res at xyMarkerColors = (/colors(i,:)/) ;this does not work
>>     res at xyMarkerColor= colors(i,:)
>>     if (i.eq.0) then
>>       plotA = gsn_csm_xy(wks,x,cdata(i,:),res)
>>     else
>>       plotB = gsn_csm_xy(wks,x,cdata(i,:),res)
>>       overlay(plotA,plotB)
>>     end if
>>     delete([/res at xyMarkers,res at xyMarkerSizes,res at xyMarkerColor/])
>>   end do
>>   draw(plotA)
>>   frame(wks)
>> end
>>
>> Cheers,
>>
>> Brandon
>>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>


-- 
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181107/4c809190/attachment.html>


More information about the ncl-talk mailing list