Re: How to split the legend into two groups?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Sat Apr 06 2013 - 15:24:13 MDT

Hi Kamal,

You didn't say what the problem is, but I'm guessing it's with these two lines:

  res@xyLineColors = colors4
  res@xyExplicitLegendLabels = labels4

Both of these resources were set previously to arrays with three elements, and now you are trying to assign just two elements to them.
NCL doesn't allow you to assign values to an existing variable if they are not the same dimensionalty.

You can do one of two things:

1. If you have NCL V6.1.2, then you can do this:

  res@xyLineColors := colors4
  res@xyExplicitLegendLabels := labels4

The ":=" forces the assignment to happen regardless of the previous size of these arrays.

2. If you have an older version of NCL, then you can do this:

  delete(res@xyLineColors)
  delete(res@xyExplicitLegendLabels)
  res@xyLineColors = colors4
  res@xyExplicitLegendLabels = labels4

--Mary

On Apr 5, 2013, at 7:23 PM, mmkamal@uwaterloo.ca wrote:

> Dear Mary,
>
>
> Thank you for creating this example. Yes, that's what I was looking
> for. I have applied your example to my case and become successful
> except some issues arises. If the total number of time series are not
> an integer multiple of the number of labels then the script is not
> working (e.g., in my case I have 11 time series which I have splitted
> 3,3,3 and 2 labels). Below I have included my code for your
> convenience (labels not working are commented)
>
>
> Thanks
> Kamal
>
>
> ===================================================
>
> ;---Set resources for colors and labels
> colors1 = (/"blue","red","darkgreen"/)
> colors2 = (/"darkorange","olivedrab","brown"/)
> colors3 = (/"peru","tomato","purple"/)
> ; colors4 = (/"navyblue","black"/)
>
> labels1 = (/"SAS","BMJ","GD"/)
> labels2 = (/"Tiedtke","MP_Eta","MP_WSM6"/)
> labels3 = (/"MP_Goddard","MP_Thompson","PBL_MRF"/)
> ; labels4 = (/"PBL_MYJ","PBL_MYNN2"/)
>
> ;---Create the four XY plots
> res@xyLineColors = colors1
> res@xyExplicitLegendLabels = labels1
> res@pmLegendParallelPosF = 0.15
>
> plot1 = gsn_csm_xy(wks,times,data(0:2,:),res)
>
> res@xyLineColors = colors2
> res@xyExplicitLegendLabels = labels2
> res@pmLegendParallelPosF = 0.37
> plot2 = gsn_csm_xy(wks,times,data(3:5,:),res)
>
> res@xyLineColors = colors3
> res@xyExplicitLegendLabels = labels3
> res@pmLegendParallelPosF = 0.59
> plot3 = gsn_csm_xy(wks,times,data(6:8,:),res)
>
> ; res@xyLineColors = colors4
> ; res@xyExplicitLegendLabels = labels4
> ; res@pmLegendParallelPosF = 0.81
> ; plot4 = gsn_csm_xy(wks,times,data(9:10,:),res)
>
> ;---Overlay one plot on the other, so they become one plot.
> overlay(plot1,plot2)
> overlay(plot1,plot3)
> ; overlay(plot1,plot4)
>
> draw(plot1) ; This will draw all four plots
> frame(wks)
>
> ===============================================================
>
>
>
>
> Quoting Mary Haley <haley@ucar.edu>:
>
>> Hi Kamal,
>>
>> Something was wrong with my mailer and I could not see your attached plot.
>>
>> I created an example for you. In order to do what I think you're asking for,
>> you need to create separate XY plots, each with a subset of the curves,
>> and its own legend. You will need to move the legend to a different place
>> so they don't overlap.
>>
>> Then, you can use te "overlay" procedure to overlay all the plots on
>> top of each other.
>>
>> See example xy_32.ncl (which I've attached) at:
>>
>> http://www.ncl.ucar.edu/Applications/overlay.shtml#ex32
>>
>> --Mary
>>
>>
>
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Apr 6 15:24:23 2013

This archive was generated by hypermail 2.1.8 : Sun Apr 07 2013 - 21:13:30 MDT