Mercurial > octave-nkf
comparison scripts/plot/__render_plot1__.m @ 6178:830235f4984f
[project @ 2006-11-17 00:16:57 by jwe]
author | jwe |
---|---|
date | Fri, 17 Nov 2006 00:19:18 +0000 |
parents | |
children | ac4821cdb740 |
comparison
equal
deleted
inserted
replaced
6177:6ac0c826459e | 6178:830235f4984f |
---|---|
1 ## Copyright (C) 2006 John W. Eaton | |
2 ## | |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 2, or (at your option) | |
8 ## any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, write to the Free | |
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
18 ## 02110-1301, USA. | |
19 | |
20 function __render_plot1__ (mxi, myi) | |
21 | |
22 __plot_globals__; | |
23 | |
24 cf = __current_figure__; | |
25 | |
26 if (! isempty (__plot_data__{cf}{mxi,myi})) | |
27 | |
28 have_image = false; | |
29 | |
30 for j = 1:length (__plot_data__{cf}{mxi,myi}) | |
31 if (__plot_data_type__{cf}{mxi,myi}(j) == 1) | |
32 have_image = true; | |
33 endif | |
34 ## Do this check before sending any commands to gnuplot so that if | |
35 ## there is an error, we don't leave things in a bad state. | |
36 if (j == 1) | |
37 first_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j); | |
38 this_plot_data_type = first_plot_data_type; | |
39 else | |
40 this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j); | |
41 if ((first_plot_data_type != 3 && this_plot_data_type == 3) | |
42 || (first_plot_data_type == 3 && this_plot_data_type != 3)) | |
43 error ("can't mix 2-d and 3-d data in the same plot"); | |
44 endif | |
45 endif | |
46 endfor | |
47 | |
48 if (have_image) | |
49 __gnuplot_raw__ ("set size ratio -1;\n"); | |
50 | |
51 cmap = __plot_image_colormap__{cf}{mxi,myi}; | |
52 | |
53 palette_size = rows (cmap); | |
54 __gnuplot_raw__ (sprintf ("set palette positive color model RGB maxcolors %i\n", | |
55 palette_size)); | |
56 | |
57 __gnuplot_raw__ ("set palette file \"-\"\n"); | |
58 tmp = round (1000 * cmap) / 1000; | |
59 tmp_rows = rows (tmp); | |
60 idx = (0:tmp_rows-1)'; | |
61 __gnuplot_raw__ (sprintf ("%d %.4g %.4g %.4g\n", [idx, tmp]')); | |
62 __gnuplot_raw__("e\n"); | |
63 | |
64 __gnuplot_raw__ ("set autoscale fix\n"); # "fix" is helpful for "a" hotkey | |
65 __gnuplot_raw__ ("set tics out\n"); | |
66 endif | |
67 | |
68 first = true; | |
69 | |
70 for j = 1:length (__plot_data__{cf}{mxi,myi}) | |
71 | |
72 this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j); | |
73 | |
74 for i = 1:length (__plot_data__{cf}{mxi,myi}{j}) | |
75 | |
76 if (first) | |
77 first = false; | |
78 __do_legend__ (); | |
79 if (first_plot_data_type == 3) | |
80 cmd = gnuplot_command_splot; | |
81 else | |
82 cmd = gnuplot_command_plot; | |
83 endif | |
84 __gnuplot_raw__ (sprintf ("%s ", cmd)); | |
85 else | |
86 __gnuplot_raw__ (",\\\n"); | |
87 endif | |
88 | |
89 if (this_plot_data_type == 1) | |
90 label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i}); | |
91 | |
92 tmp = __plot_image_dims__{cf}{mxi,myi}{j}{i}; | |
93 | |
94 x_dim = tmp(1); | |
95 y_dim = tmp(2); | |
96 x_origin = tmp(3); | |
97 y_origin = tmp(4); | |
98 dx = tmp(5); | |
99 dy = tmp(6); | |
100 | |
101 A = __plot_data__{cf}{mxi,myi}{j}{i}; | |
102 | |
103 ## Let the file be deleted when Octave exits or | |
104 ## `purge_tmp_files' is called. | |
105 [fid, binary_file_name, msg] ... | |
106 = mkstemp (strcat (P_tmpdir, "/gpimageXXXXXX"), 1); | |
107 | |
108 ## Gnuplot reads binary files very quickly. However, the | |
109 ## 'fwrite' below is much slower than using the current | |
110 ## '__gnuplot_plot__' command. | |
111 fwrite (fid, A(:), "float"); | |
112 fclose (fid); | |
113 | |
114 __gnuplot_raw__ (sprintf ("\"%s\" binary array=%dx%d scan=yx flipy origin=(%g,%g) dx=%g dy=%g using 1 %s '%s' with image", | |
115 binary_file_name, x_dim, y_dim, x_origin, | |
116 y_origin, dx, dy, | |
117 gnuplot_command_title, label)); | |
118 else | |
119 usingstr = __plot_usingstr__{cf}{mxi,myi}{j}{i}; | |
120 fmtstr = __plot_fmtstr__{cf}{mxi,myi}{j}{i}; | |
121 withstr = __plot_withstr__{cf}{mxi,myi}{j}{i}; | |
122 | |
123 label = undo_string_escapes (__plot_key_labels__{cf}{mxi,myi}{j}{i}); | |
124 | |
125 __gnuplot_raw__ (sprintf ("'-' %s %s '%s' %s %s %s", usingstr, | |
126 gnuplot_command_title, label, fmtstr, | |
127 withstr)); | |
128 endif | |
129 endfor | |
130 endfor | |
131 | |
132 for j = 1:length (__plot_data__{cf}{mxi,myi}) | |
133 for i = 1:length (__plot_data__{cf}{mxi,myi}{j}) | |
134 this_plot_data_type = __plot_data_type__{cf}{mxi,myi}(j); | |
135 if (this_plot_data_type != 1) | |
136 if (this_plot_data_type == 3) | |
137 parametric = __plot_data_parametric__{cf}{mxi,myi}{j}{i}; | |
138 else | |
139 parametric = false; | |
140 endif | |
141 __gnuplot_send_inline_data__ (__plot_data__{cf}{mxi,myi}{j}{i}, | |
142 this_plot_data_type, parametric); | |
143 endif | |
144 endfor | |
145 endfor | |
146 | |
147 if (! first) | |
148 __gnuplot_raw__ ("\n"); | |
149 endif | |
150 | |
151 endif | |
152 | |
153 endfunction |