Difference between revisions of "Color-coded maps with 2d histograms, png, and xfig (xfig example)"
Line 1: | Line 1: | ||
[[Category:SLxfig]] | [[Category:SLxfig]] | ||
− | + | <b>example added by Felix</b> | |
There are many examples, where a color-coded map (or landscape) shows the results best, for example when showing the energy-dependence of the pulse profile of pulsar. All data depending on two parameters (in the example the count-rate depends on energy and on phase) can be displayed conveniently in this way. Another popular example is to show the χ² landscape as function of two fit-parameters on such a map instead of only showing the confidence contours. | There are many examples, where a color-coded map (or landscape) shows the results best, for example when showing the energy-dependence of the pulse profile of pulsar. All data depending on two parameters (in the example the count-rate depends on energy and on phase) can be displayed conveniently in this way. Another popular example is to show the χ² landscape as function of two fit-parameters on such a map instead of only showing the confidence contours. | ||
Line 47: | Line 47: | ||
And voilá, <code>mymap.eps</code> contains our colorful map with the axes-labeled correctly. | And voilá, <code>mymap.eps</code> contains our colorful map with the axes-labeled correctly. | ||
− | + | === Outlook === | |
This example shows a very basic plot. It can quite easily extended, for example by plotting a scale next to it (for example [[http://jedsoft.org/fun/slxfig/examples.html|SLxfig Plotting Examples, Example 6]], click on the image to see the code). Or you could whish that the <code>y</code>-dimension of each pulse profile should represent its width in energy space, then you could make a new array with a lot of more rows in <code>y</code> direction, were you write in every row the same pulse profile between a given energy range. Or you could want to define your own colormap, this can be done with <code>png_add_colormap</code>. | This example shows a very basic plot. It can quite easily extended, for example by plotting a scale next to it (for example [[http://jedsoft.org/fun/slxfig/examples.html|SLxfig Plotting Examples, Example 6]], click on the image to see the code). Or you could whish that the <code>y</code>-dimension of each pulse profile should represent its width in energy space, then you could make a new array with a lot of more rows in <code>y</code> direction, were you write in every row the same pulse profile between a given energy range. Or you could want to define your own colormap, this can be done with <code>png_add_colormap</code>. | ||
The [[Example:_two-dimensional_histograms|second example]] illustrates [[Example:_two-dimensional_histograms|two-dimensional histograms]]. | The [[Example:_two-dimensional_histograms|second example]] illustrates [[Example:_two-dimensional_histograms|two-dimensional histograms]]. |
Revision as of 14:57, 13 April 2018
example added by Felix
There are many examples, where a color-coded map (or landscape) shows the results best, for example when showing the energy-dependence of the pulse profile of pulsar. All data depending on two parameters (in the example the count-rate depends on energy and on phase) can be displayed conveniently in this way. Another popular example is to show the χ² landscape as function of two fit-parameters on such a map instead of only showing the confidence contours.
A second example illustrates two-dimensional histograms, which can be displayed in a very similar way.
Preparation
First of all, we need a 2d array A[y,x]. Let's stick to the energy dependent pulse profiles and assume we have four proiles pp1, pp2, pp3, and pp4 with 64 phase bins each, i.e pp# = Double_Type[64]. We could than produce A by writing
variable A = Double_Type[4,64] ; A[0,*] = pp1 ; A[1,*] = pp2 ; A[2,*] = pp3 ; A[3,*] = pp4 ;
Making the image
The easiest way to plot a 2d array like that is to use
plot_image(A) ;
But this gives us only a black and white image of the array.
It's much nicer to use the S-lang "PNG" module, which allows to save the plot as a PNG file.
require("png") ; % not necessary if isisscripts have been loaded
First of all, we'd like to transfer our array to an image of RGB values. This can be achieved using a color map (the png_get_colormap_names
function returns the names of all available color maps):
variable a_pic = png_gray_to_rgb(A, "rainbow") ;
Writing out is easy, just give the filename and the new array a_pic
png_write_flipped("mymap.png", a_pic) ; % _flipped to get x and y axes right
Adding axes to the image
So far, so good, but the mymap.png
is not really informative at the moment as it lacks the important information which parameters were plotted. This can be easily achieved by using the x-fig module.
First we need to creat a new xfig
structure:
require("xfig") ; % not necessary if isisscripts have been loaded variable map = xfig_plot_new(11,11) ;
Define the coordinates (xmin, xmax, ymin, ymax)
, assuming that pp1 starts at 5keV and pp4 ends at 100keV.
map.world(0, 1, 5, 100) ;
Load the PNG-file
map.plot_png("mymap.png") ;
Write labels
map.xlabel("Pulse phase") ; map.ylabel("Energy [keV]") ;
Render all of that to an EPS file:
map.render("mymap.eps") ;
And voilá, mymap.eps
contains our colorful map with the axes-labeled correctly.
Outlook
This example shows a very basic plot. It can quite easily extended, for example by plotting a scale next to it (for example [Plotting Examples, Example 6], click on the image to see the code). Or you could whish that the y
-dimension of each pulse profile should represent its width in energy space, then you could make a new array with a lot of more rows in y
direction, were you write in every row the same pulse profile between a given energy range. Or you could want to define your own colormap, this can be done with png_add_colormap
.
The second example illustrates two-dimensional histograms.