爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 650|回复: 4

[作图] 【已解决】NCL画椭圆,如何给椭圆填色

[复制链接]
回帖奖励 50 金钱 回复本帖可获得 10 金钱奖励! 每人限 1 次
发表于 2025-2-23 23:09:18 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
本帖最后由 xshjbds 于 2025-3-1 11:37 编辑

NCL画椭圆,有朋友知道如何给椭圆填色吗?尝试了gsFillColor和cnFillColor没有成功,或许还有其他方法?附代码如下:
; add ellipses
    resc                  = True
    resc@gsLineColor      = "Black"
    resc@gsFillColor      = "Black"
    resc@gsLineThicknessF = 3
    resc@Scale            = 2.5
    resc@Rotation         = -90
    circle_ll(wks,map1,105,-5,5,resc)

--------------------------------------------------------------------------------
【解决方案】使用polygon画填色椭圆并旋转
; add ellipses--polygon
    ; 计算椭圆的经纬度坐标
    x0 = 140.0  
    y0 = -10.0  
    a  = 10.0
    b  = 6.0
    npts  = 100
    angle = -25.0

    PI  = get_pi("double")
    theta = fspan(0, 2 * PI, npts)
    x = a * cos(theta) + x0
    y = b * sin(theta) + y0

    ; transfer angle to rad
    angle_rad = angle * PI / 180.0
    ; Rotation
    x_rot = (x-x0) * cos(angle_rad) - (y-y0) * sin(angle_rad)+x0
    y_rot = (x-x0) * sin(angle_rad) + (y-y0) * cos(angle_rad)+y0

    ; resources
    resd = True      
    resd@gsFillColor      = "red"      
    resd@gsLineColor      = "red"     
    resd@gsLineThicknessF = 2.0   
    resd@gsFillOpacityF = 0.5     

    ellipse1  = gsn_add_polygon(wks, map1, x_rot,y_rot, resd)






密码修改失败请联系微信:mofangbao
发表于 2025-2-26 10:36:49 | 显示全部楼层

回帖奖励 +10 金钱

; 创建工作站
wks = gsn_open_wks("png", "filled_ellipse")

; 创建一个空白图
res = True
res@gsnDraw = False
res@gsnFrame = False
plot = gsn_csm_blank_plot(wks, res)

; 椭圆参数设置
center_x = 0.5  ; 椭圆中心x坐标
center_y = 0.5  ; 椭圆中心y坐标
a = 0.3         ; 长轴半径
b = 0.2         ; 短轴半径
npoints = 100   ; 用于近似椭圆的点数量

; 创建椭圆的点集合
angle = fspan(0, 2*3.14159, npoints)  ; 0到2π之间的角度
x = center_x + a*cos(angle)
y = center_y + b*sin(angle)

; 设置填充的颜色和样式
gsres = True
gsres@gsFillColor = "red"  ; 填充颜色设置为红色
gsres@gsFillOpacityF = 0.7 ; 透明度设置(可选)

; 添加填充椭圆到图中
polygon = gsn_add_polygon(wks, plot, x, y, gsres)

; 可选:添加椭圆轮廓
lnres = True
lnres@gsLineColor = "black"  ; 轮廓线颜色
lnres@gsLineThicknessF = 2.0 ; 轮廓线粗细
outline = gsn_add_polyline(wks, plot, x, y, lnres)
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

发表于 2025-2-25 18:01:41 | 显示全部楼层

回帖奖励 +10 金钱

试试这个?
; tpres        = True
; tpres@gsFillColor = "grey80"
; shp_plot3  = gsn_add_shapefile_polygons(wks, plot1,shptp, tpres)
shptp是我的shp文件
密码修改失败请联系微信:mofangbao
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2025-3-1 11:11:00 | 显示全部楼层
zhoushiyang123 发表于 2025-2-26 10:36
; 创建工作站
wks = gsn_open_wks("png", "filled_ellipse")

非常感谢!已经解决,就是用polygon画椭圆
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

 楼主| 发表于 2025-3-1 11:14:08 | 显示全部楼层
guoguohh 发表于 2025-2-25 18:01
试试这个?
; tpres        = True
; tpres@gsFillColor = "grey80"

非常感谢!
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表