[ncl-talk] How to create two y axis with a common x axis in bar plot
Mary Haley
haley at ucar.edu
Mon Aug 4 08:29:44 MDT 2014
Ipsita,
In order to overlay a bunch of bar charts, it works best if you can shift
each of the bars by a certain bar width, and then you can draw them
side-by-side. I think you may have used part of bar_11.ncl on our bar
examples page, and this is a good one to work with. However, you want to
add some overlay code in there, which will make all the plots part of the
same plot.
The key is to draw each set of bars with a slightly shifted set of X
values, so the bars are drawn next to each other.
See the attached example and script.
--Mary
On Fri, Aug 1, 2014 at 4:27 PM, Ipshita Majhi <ipmajhi at alaska.edu> wrote:
> Hi,
> I want to plot trend values and monthly means in one plot. Both are an
> array of size 12 .
> The program gives no error but the plot are overlapping. I am not sure how
> to fix it. I realized that if I use the below mentioned method they overlap
> is there a way to have two y axis in bar plots. Since the trends are much
> smaller then avgs.
>
> ;*****************************************************
> ;Trend and monthly climatology together in one bar plot
> ;*******************************************************
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> months=(/1,2,3,4,5,6,7,8,9,10,11,12/)
>
>
> monthly_avg=asciiread("~/Documents/PhD_June_2015/NCL_Moonsoon/Data_output/Monthly_avg_air.txt",-1,
> "float")
>
> monthly_Trend=asciiread("~/Documents/PhD_June_2015/NCL_Moonsoon/Data_output/trend_air.txt",
> -1, "float")
> printVarSummary(monthly_avg)
>
> wks = gsn_open_wks("ps","Trend_Avg")
>
>
> sres = True
> sres at vpWidthF = 0.7
> sres at vpHeightF = 0.5
> sres at gsnDraw = True
> sres at gsnFrame = False
> sres at gsnXYBarChart = True
> sres at gsnXYBarChartBarWidth = 0.15 ; change bar widths
> sres at tmXBMode = "Explicit" ; explicit labels
> sres at tmXBValues = (/1,2,3,4,5,6,7,8,9,10,11,12/)
> sres at tmXBLabels =
> (/"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"/)
> sres at tmXBLabelFontHeightF = 0.0205
> sres at tmXTLabelFontHeightF = 0.0205
> sres at tmYLLabelFontHeightF = 0.0225
> sres at tiMainFontHeightF = 0.025
> sres at tiMainFont = "helvetica"
> sres at tiMainString = "All India Rainfall Climatology and Trend
> 1880-2012"
> sres at tiYAxisString = "(mm)"
>
> plot1 = gsn_csm_xy (wks,months,monthly_avg,sres)
> sres at gsnXYBarChartColors = (/"red"/) ;
> seperately, not
> plot2 = gsn_csm_xy(wks,months,monthly_Trend,sres)
> ; advancing the frame
> sres at gsnXYBarChartColors = (/"blue"/) ; but
> tweaking where
>
>
> _______________________________________________
> ncl-talk mailing list
> 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/20140804/b04f1178/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bar.png
Type: image/png
Size: 42598 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140804/b04f1178/attachment.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bar_11.ncl
Type: application/octet-stream
Size: 3061 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140804/b04f1178/attachment.obj
More information about the ncl-talk
mailing list