|
|
|
|
Gallery: Axis styles and grids (Python)Examples
The default plot style is to show all four axes (closed)
add_curve("atan.fits[cols X,Y]",["symbol.style","none"])
The open plot style only displays two axes
plt = ChipsPlot()
plt.style = "open"
crv = ChipsCurve()
crv.symbol.style = "none"
add_curve("atan.fits[cols X,Y]",[plt,crv])
An alternative way of saying this in one command is:
add_curve("atan.fits[cols X,Y]", ["plot.style", "open", "symbol.style", "none"])
The boxed plot style draws a box around the plot
plt = ChipsPlot()
plt.style = "boxed"
crv = ChipsCurve()
crv.symbol.style = "none"
add_curve("atan.fits[cols X,Y]",[plt,crv])
# We hide the axes to show the box surrounding the plot
hide_axis()
set_plot(["leftmargin",0.1,"bottommargin",0.1])
Although the axes have been hidden, the data is still displayed and the data range can still be changed; after the limits call below the plot changes to display the new range.
chips> get_plot_xrange()
[-5.75, 10.75]
chips> get_plot_yrange()
[-1.5156271890074535, 1.6133540963661723]
chips> limits (Y_AXIS, -2, 2)
chips> get_plot_yrange()
[-2.0, 2.0]
chips> get_plot_xrange; [-5.75, 10.75] chips> get_plot_yrange; [-1.5156271890074535, 1.6133540963661723] chips> limits (Y_AXIS, -2, 2); chips> get_plot_yrange; [-2.0, 2.0] Numeric labels (ticklabels) on all four axes
add_curve("atan.fits[cols X,Y]",["symbol.style","none"])
set_plot(["rightmargin",0.15])
set_axis("all",["ticklabel.visible",1,"ticklabel.offset",10])
The plot created by the add_curve call contains two axes: the X axis (ax1) at the bottom of the plot and the Y axis (ay1) at the left of the plot. There are also four borders which run along the edges of the plot: it is these that are controlled by the plot.style attribute, although you generally do not see the bx1 and by1 borders since they are hidden by the axes. These borders are set up to automatically mirror the main axes; they are bound to ax1 or ay1 so that any changes to the limits, scaling, or tickmarks in the axes are also applied to the borders. This can be seen if you use the info_bound_axes call, which returns:
chips> print info_bound_axes()
Window [win1]
Frame [frm1]
plot1:bx1 -> plot1:bx2
plot1:by1 -> plot1:by2
plot1:ax1 -> plot1:bx2
plot1:ay1 -> plot1:by2
This says that the top and bottom borders (bx1 and bx2) are bound to each other and then to the X axis (ax1), and that the left and right borders (by1 and by2) are similarly bound to the Y axis (ay1). The properties of borders can be changed using the set_axis call, either explicitly by giving a name - e.g.
set_xaxis("bx2", ["ticklabel.color", "green"])
or implicitly by the use of the "all" value, as done in this example. Unlike other ChIPS objects, borders can not be created nor can their names be changed. They are included in the output of info as shown below:
chips> print info()
Window [win1]
Frame [frm1]
Plot [plot1] (0.15,0.15) .. (0.85,0.90)
Border bottom [bx1] top [bx2] left [by1] right [by2]
X Axis [ax1]
Y Axis [ay1]
Curve [crv1]
Changes in CIAO 4.1
Rotating the numbers along an axis
add_curve("aspect.fits[cols ra,dec]",["symbol.style","none"])
set_xaxis(["ticklabel.angle",40.0,"ticklabel.offset",16])
The properties of an axis can be found using one of the get_xaxis, get_yaxis, or get_axis routines. Here we display the X axis attributes after creating the plot above: chips> print get_xaxis() automax = True automin = True color = default depth = 100 id = None label.angle = 0.0 label.color = default label.font = helvetica label.fontstyle = normal label.halign = 0.5 label.size = 14 label.valign = 0.0 label.visible = True majorgrid.color = default majorgrid.style = 6 majorgrid.thickness = 1.0 majorgrid.visible = False majortick.color = default majortick.count = 6 majortick.interval = 10.0 majortick.length = 4 majortick.mode = limits majortick.style = inside majortick.thickness = 1.0 majortick.visible = True minorgrid.color = default minorgrid.style = 2 minorgrid.thickness = 1.0 minorgrid.visible = False minortick.color = default minortick.count = 3 minortick.interval = 5.0 minortick.length = 2 minortick.mode = count minortick.style = inside minortick.thickness = 1.0 minortick.visible = True offset.parallel = 0.0 offset.perpendicular = 40.0 pad = 0.05 thickness = 1.0 tickformat = %g ticklabel.angle = 40.0 ticklabel.color = default ticklabel.font = helvetica ticklabel.fontstyle = normal ticklabel.halign = -99.0 ticklabel.offset = 16 ticklabel.size = 12 ticklabel.style = outside ticklabel.valign = -99.0 ticklabel.visible = True tickstyle = inside x.label = None x.stem = None y.label = None y.stem = None Changes in CIAO 4.1
Changing the format used to display the labels
add_curve("aspect.fits[cols time,roll]",["symbol.style","none"])
set_plot(["bottommargin",0.25])
set_yaxis(["tickformat","%.3f"])
ax = ChipsAxis()
ax.tickformat = "%.5z"
ax.ticklabel.angle = 40.0
ax.ticklabel.offset = 30
set_xaxis(ax)
set_axis(["ticklabel.fontstyle","bolditalic"])
Axes can be labelled in a number of ways: there are a variety of formats that can be used - including sexagesimal notation - and the arrangement of major and minor tick marks can be adjusted, as shown in later examples (mode=interval and mode=count). Changes in CIAO 4.1
Using sexagesimal notation for the axis labels
add_curve("aspect.fits[cols ra,dec]",["symbol.style","none"])
set_xaxis(["tickformat","ra"])
set_yaxis(["tickformat","dec"])
Changing the number of major tick marks (using mode=interval)
add_curve("aspect.fits[cols ra,dec]",["symbol.style","none"])
set_xaxis(["majortick.interval",5.0e-3,"majortick.mode","interval"])
ay = ChipsAxis()
ay.majortick.interval = 2.0e-3
ay.majortick.mode = "interval"
ay.minortick.count = 3
set_yaxis(ay)
Changing the number of major tick marks (using mode=count)
add_curve("aspect.fits[cols ra,dec]",["symbol.style","none"])
set_axis(["majortick.count",4,"majortick.mode","count"])
# Override the minortick.count setting for the Y axis
set_yaxis(["minortick.count",3])
Displaying a grid at the major tick mark locations
add_curve("atan.fits[cols X,Y]",["symbol.style","none"])
set_axis(["majorgrid.visible",1,"majorgrid.style","dot"])
Add a grid at the major and minor tick mark locations
crv = ChipsCurve()
crv.symbol.style = "none"
crv.line.thickness = 2
crv.line.color = "red"
add_curve("atan.fits[cols X,Y]",crv)
ax = ChipsAxis()
ax.majortick.mode = "interval"
ax.majortick.interval = 10.0
ax.minortick.count = 1
set_xaxis(ax)
ay = ChipsAxis()
ay.majortick.mode = "interval"
ay.majortick.interval = 1.5
ay.minortick.count = 2
set_yaxis(ay)
set_axis(["majorgrid.visible",1,"minorgrid.visible",1])
limits(Y_AXIS,-1.6,1.6)
In this example we have created grid lines at the major and minor tick-mark locations. We use different line styles to improve visibility, and adjusted the spacing to the major and minor tick marks so as to change the grid spacing.
Grids work with logarithmically-scaled axes too
|
![]() |
The Chandra X-Ray
Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA. Email: cxcweb@head.cfa.harvard.edu Smithsonian Institution, Copyright © 1998-2004. All rights reserved. |