changeset 19451:cdb6bc186c42

Fix ploting 1D images with gnuplot (bug #43836). * __go_draw_axes__.m: Correct dx and dy, which are 0 for 1D images, to be 0.5.
author Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
date Tue, 16 Dec 2014 17:25:47 +0100
parents 06b23f224f52
children 06931d787450
files scripts/plot/util/private/__go_draw_axes__.m
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/private/__go_draw_axes__.m	Sun Dec 21 17:38:14 2014 -0500
+++ b/scripts/plot/util/private/__go_draw_axes__.m	Tue Dec 16 17:25:47 2014 +0100
@@ -157,7 +157,7 @@
       [tt, f, s] = __maybe_munge_text__ (enhanced, t, "string");
       fontspec = create_fontspec (f, s, gnuplot_term);
       fprintf (plot_stream, "set title \"%s\" %s %s %s;\n",
-               undo_string_escapes (tt), fontspec, colorspec, 
+               undo_string_escapes (tt), fontspec, colorspec,
                __do_enhanced_option__ (enhanced, t));
     endif
   endif
@@ -513,6 +513,9 @@
           img_ydata = img_ydata(1) + [0, rows(img_data)-1];
         endif
 
+        x_origin = min (img_xdata);
+        y_origin = min (img_ydata);
+
         [y_dim, x_dim] = size (img_data(:,:,1));
         if (x_dim > 1)
           dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1);
@@ -520,6 +523,11 @@
           x_dim = 2;
           img_data = [img_data, img_data];
           dx = abs (img_xdata(2)-img_xdata(1));
+          if (dx < 1)
+            ## Correct gnuplot string for 1-D images
+            dx       = 0.5;
+            x_origin = 0.75;
+          endif
         endif
         if (y_dim > 1)
           dy = abs (img_ydata(2)-img_ydata(1))/(y_dim-1);
@@ -527,11 +535,13 @@
           y_dim = 2;
           img_data = [img_data; img_data];
           dy = abs (img_ydata(2)-img_ydata(1));
+          if (dy < 1)
+            ## Correct gnuplot string for 1-D images
+            dy       = 0.5;
+            y_origin = 0.75;
+          endif
         endif
 
-        x_origin = min (img_xdata);
-        y_origin = min (img_ydata);
-
         if (ndims (img_data) == 3)
           data{data_idx} = permute (img_data, [3, 1, 2])(:);
           format = "1:2:3";
@@ -2131,7 +2141,7 @@
                     plot_stream, mirror, mono, axispos, tickdir, ticklength,
                     fontname, fontspec, interpreter, scale, sgn, gnuplot_term)
   persistent warned_latex = false;
-  
+
   ## Avoid emitting anything if the tics are empty, because this undoes the
   ## effect of the previous unset xtics and thereby adds back in the tics.
   if (isempty (tics))
@@ -2626,4 +2636,3 @@
                           axis_obj.tickdir);
   endif
 endfunction
-