[ncl-talk] legend font size
Gerard Ketefian - NOAA Affiliate
gerard.ketefian at noaa.gov
Wed Sep 16 12:39:55 MDT 2015
Thanks Mary and David. Mary's suggestion solved my font size issue.
I have a follow-up question I'm hoping you can help me with. I'd like to
make the color lines within the legend the same actual length (e.g. as
measured in inches on paper) regardless of the length of the longest legend
label (text). Also, I'd like to make the distance from the left edge of
the legend box to the start of the lines the same physical distance, again
regardless of the lengths of the legend labels.
What I'm trying to do is to have a legend that only changes on its right
side when I have longer legend labels (by having the legend box width
extend only to the right to accommodate the longer label(s)). I'd like the
left portion of the legend (where the lines are) to stay exactly the same
in terms of the positions and physical dimensions of the various items.
I modified my previous code (see attached test_legend2.ncl) to try out some
cases, but I haven't been able to get things to work yet. When I have
labels that aren't too long, the legend lines are, as expected, a factor
lgBoxMinorExtentF of the width of the legend box
(test_legend_short_label.png), but when they are long, the legend lines get
squished to some factor smaller than the specified lgBoxMinorExtentF
(test_legend_long_label.png).
I'd appreciate any suggestions on how to solve this issue.
Thanks again,
Gerard
On Wed, Sep 16, 2015 at 11:32 AM, David Brown <dbrown at ucar.edu> wrote:
> I will look into this question.
> -dave
>
> On Tue, Sep 15, 2015 at 5:20 PM, Mary Haley <haley at ucar.edu> wrote:
> > Hi Gerard,
> >
> > I'm hoping Dave Brown will step in and correct me if I'm wrong, but I
> think
> > the resizing of the legend labels is going to happen no matter what,
> because
> > it's trying to fit everything inside the legend box.
> >
> > You can work around this by using gsn_create_legend (instead of
> > gsn_legend_ndc) to create the legend with the same resources as before,
> and
> > then use setvalues to reset the lgLabelFontHeightF resource to be what
> you
> > originally wanted it to be. Setvalues will simply change the resource
> value
> > of an existing object, and the legend manager doesn't enter the picture
> and
> > try to shrink your labels.
> >
> > It's a kludge, but I think it should work. here's what the old code looks
> > like:
> >
> > gsn_legend_ndc(wks_png, num_curves, legend_labels, 0.20, 0.35, lgres)
> > frame(wks_png)
> >
> > And here's what the new code should look like:
> >
> > ;---gsn_create_legend creates the legend, but doesn't draw it
> > legend_id = gsn_create_legend(wks_png, num_curves, legend_labels,
> lgres)
> >
> > ;---Reset lgLabelFontHeightF to the desired value
> > setvalues legend_id
> > "lgLabelFontHeightF" : lgres at lgLabelFontHeightF
> > end setvalues
> >
> > ;--Now draw the legend
> > draw(legend_id)
> > frame(wks_png)
> >
> > You may need to place with lgres at vpXF and legres at vpYF to position the
> legend
> > as desired.
> >
> > --Mary
> >
> >
> > On Mon, Sep 14, 2015 at 11:19 PM, Gerard Ketefian - NOAA Affiliate
> > <gerard.ketefian at noaa.gov> wrote:
> >>
> >> Hi,
> >>
> >> I'd like to generate a legend in which the font size of the item labels
> is
> >> the same regardless of the length (i.e. the number of characters) of the
> >> item labels. I'm using gsn_legend_ndc(...) to add the legend to my
> plot.
> >>
> >> The problem I'm having is that NCL is adjusting the font size (I suppose
> >> to always fit the labels within the width of the legend box), and I'm
> not
> >> getting the font size that I'd like.
> >>
> >> I've attached an NCL script (test_legend.ncl) that generates png files
> >> showing what happens when:
> >>
> >> 1) No adjustments are made to any legend resources (case of
> manual_manage
> >> set to False in the script). I tried a case of short legend labels
> >> (test_legend_autoManage_short_labels.png) and another with long ones
> >> (test_legend_autoManage_long_labels.png). You can see that NCL adjusts
> the
> >> font size, I suppose to fit it within the legend box width.
> >>
> >> 2) Adjustments are made to several legend resources, including setting
> >> lgAutoManage to False (case of manual_manage set to False in the
> script) and
> >> setting a specific value for lgLabelFontHeightF. According to the
> online
> >> documentation, in this case NCL should not adjust the font size, and I
> >> should get whatever font size I specified via lgLabelFontHeightF.
> Again I
> >> tried a case of both short (test_legend_manualManage_short_labels.png)
> and
> >> long (test_legend_manualManage_long_labels.png) legend labels. You can
> see
> >> that again, NCL adjusted the font size.
> >>
> >> Any idea how I can make NCL use the font size I specified, without any
> >> automatic adjustments?
> >>
> >> Thanks,
> >> Gerard
> >>
> >>
> >> _______________________________________________
> >> ncl-talk mailing list
> >> ncl-talk at ucar.edu
> >> List instructions, subscriber options, unsubscribe:
> >> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> >>
> >
> >
> > _______________________________________________
> > ncl-talk mailing list
> > ncl-talk at ucar.edu
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150916/e40c1068/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_legend2.ncl
Type: application/octet-stream
Size: 10500 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150916/e40c1068/attachment.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_legend_short_label.png
Type: image/png
Size: 130162 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150916/e40c1068/attachment.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_legend_long_label.png
Type: image/png
Size: 138184 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150916/e40c1068/attachment-0001.png
More information about the ncl-talk
mailing list