Paul Bryan <[email protected]> writes:

Attached is a patch to fix this.

>> Actual: when the table contains column headers, the explicit labels:
>> argument is
>> ignored
>
> Confirmed.
>
> I can reproduce this, but I'm getting some even stranger
> behaviour. Using the provided example:
>
>> #+attr_html: :width 50%
>> #+plot: title:"Temperatures 2026-06-27" with:"linespoints lw 3"
>> <file:"measured-temperature.png>" timeind:1 timefmt:"%H:%M"
>> set:"format x '%H:%M'"
>> #+plot: labels:("Time" "Terrace South" "Westside" "Eastside" "Next Morning")
>> #+plot: set:"xlabel 'daytime / HH:MM'" set:"ylabel 'temperature / °C'"
>> |  time |   T1 |   T2 |   T3 |  T4* |
>> |-------+------+------+------+------|
>> |  7:30 |      |      |      | 28.8 |
>> |  8:14 | 32.3 | 31.1 |      |      |
>> |  9:14 | 33.3 | 32.8 |      |      |
>> ...
>
> If I execute `org-plot-gnuplot' on the #+plot: line, or anywhere in
> the table, I get the labels. If I execute it on any other line,
> including the line just after the table, I get the column headings
> instead.

I found out what caused the strange behaviour I was seeing as well as the 
original bug. Omitting irrelevant steps, the code was doing:

1. jump to table and collect options (labels set here if included in options)
2. jump to table and get table headers (labels set here if the table has 
headers, overwriting any previously set labels in step 1)
3. collect options at point without jumping to table (overwriting labels again 
if there are labels set *at point or above*)

The fix I have is to remove step 3 and to include a check in step 2 to see if 
there are labels set. If so, don't overwrite them. Note that step 1 should be 
completed before step 2 since step may be change depending on the options 
provided in step 1 (specifically if `:transpose' is `'t').

I'm not sure why step 3 was there, and without jumping to the table first. It 
may just be a holdover to some changes that never got removed. As far as I can 
tell, it should not be there.

@TEC, do you know if there is a reason for step 3, and if it's okay to remove 
it as I did?

@Dr. Arne Babenhauserheide can you check if the patch fixes your issue?

Also, I think the `org-plot/gnuplot' function could be reorganised a little to 
make it a bit cleaner (without changing functionality), but that's probably not 
really necessary. I went with a minimal fix.

Also, not sure if it would be more in line with current idioms to call it 
`org-plot-gnuplot' (with `org-plot/gnuplot' as an alias to prevent breaking 
anything). Not sure if that matters much either though.

Cheers,
Paul.
>From f3f11a6455581c3e691cb5abda44c9a0750547d0 Mon Sep 17 00:00:00 2001
From: Paul Bryan <[email protected]>
Date: Sat, 11 Jul 2026 21:21:28 +1000
Subject: [PATCH] lisp/org-plot.el: labels set by options take precedence over
 table headers

* lisp/org-plot.el (org-plot/gnuplot): labels set by options take precedence over table headers

TINYCHANGE

Reported-by: "Dr. Arne Babenhauserheide" <[email protected]>"
Link: https://list.orgmode.org/[email protected]/
---
 lisp/org-plot.el | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/lisp/org-plot.el b/lisp/org-plot.el
index 53a218b3a..bfb1fd693 100644
--- a/lisp/org-plot.el
+++ b/lisp/org-plot.el
@@ -691,15 +691,12 @@ line directly before or after the table."
 
       (unless type
 	(user-error "Org-plot type `%s' is undefined" (plist-get params :plot-type)))
-
+      ;; Set labels from table heading unless already set
       (when (eq (cadr table) 'hline)
-	(setf params
-	      (plist-put params :labels (car table))) ; headers to labels
+	(unless (plist-member params :labels)
+            (setf params
+	          (plist-put params :labels (car table)))) ; headers to labels
 	(setf table (delq 'hline (cdr table)))) ; clean non-data from table
-      ;; Collect options.
-      (save-excursion (while (and (equal 0 (forward-line -1))
-				  (looking-at "[[:space:]]*#\\+"))
-			(setf params (org-plot/collect-options params))))
       ;; Ensure that the user can override any plot parameter, and
       ;; that the parameters set by the plot type in
       ;; `org-plot/preset-plot-types' is respected.
-- 
2.55.0

Reply via email to