Sie sind hier: Startseite / Services / Data Analysis and Visualization / Visualization / Software / NCL / source codes / PyNGL example xy-plot
Info
Alle Inhalte des Nutzerportal sind nur auf Englisch verfügbar.

PyNGL example xy-plot

The python script creates a simple xy-plot using PyNGL.

Software requirements:

  • Python 2.7.x
  • Numpy 1.9.2
  • PyNGL/PyNIO 1.5.0

 

Run the xy-plot example script:

python PyNGL_xy_plot.py

 

Script PyNGL_xy_plot.py:

'''
  DKRZ PyNGL Script: PyNGL_xy_plot.py

  Description:       simple xy-plot

  11.05.15  meier-fleischer(at)dkrz.de
'''
import numpy, os
import Ngl, Nio

#--  define x and y variables
x = [10., 20.00, 30., 40.0, 50.000, 60.00, 70., 80.00, 90.000]
y = numpy.array([[0., 0.7, 1., 0.7, 0., -0.7, -1., -0.7, 0.],  \
                 [2., 2.7, 3., 2.7, 2.,  1.3,  1.,  1.3, 2.],  \
                 [4., 4.7, 5., 4.7, 4.,  3.3,  3.,  3.3, 4.]],'f')
                 
#-- open a workstation
wkres           =  Ngl.Resources()                  #-- generate an resources object for workstation
wkres.wkWidth   =  1024                             #-- width of workstation
wkres.wkHeight  =  1024                             #-- height of workstation
wks_type        = "png"                             #-- output type of workstation
wks             =  Ngl.open_wks(wks_type,"Py_xy",wkres)  #-- open workstation

#-- set resources
res                        =  Ngl.Resources()       #-- generate an res object for plot
res.tiXAxisString          = "x-values"             #-- x-axis title
res.tiYAxisString          = "y-values"             #-- y-axis title

#-- xy-plot resources
res.xyLineColors           =  ["red","green","blue"]#-- set 3 different colors for lines
res.xyLineThicknessF       =  3.0                   #-- line thickness for all
res.xyExplicitLegendLabels = ["t1","t2","t3"]       #-- set explicit legend labels

#-- legend resources
res.pmLegendDisplayMode    = "Always"               #-- turn on the drawing
res.pmLegendZone           =  0                     #-- legend zone: 0 = topLeft; 6 = topRight
res.pmLegendOrthogonalPosF =  0.32                  #-- move the legend upwards
res.lgJustification        = "BottomRight"          #-- legend justification
res.pmLegendWidthF         =  0.2                   #-- change width
res.pmLegendHeightF        =  0.10                  #-- change height
res.pmLegendSide           = "Top"                  #-- Change location
res.lgPerimOn              =  False                 #-- turn off the perimeter

#-- draw the plot
plot = Ngl.xy(wks,x,y,res)

#-- done
Ngl.end()

Plot result:

PyNGL xy-plot w400

Artikelaktionen