Menu

#2789 boxplot does not add label when using the every specificier

None
closed-fixed
nobody
None
2025-06-04
2025-04-17
Anonymous
No

gnuplot 6.0.0
Linux alex 6.11.0-21-generic #21~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Feb 24 16:52:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This works as expected:
plot 'box.txt' using (1):2:(0.5):('A') index 0 every :::0::0 with boxplot

This does not put the label B on the x axis.
plot 'box.txt' using (1):2:(0.5):('B') index 0 every :::1::1 with boxplot

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Discussion

  • Ethan Merritt

    Ethan Merritt - 2025-04-18

    I can't diagnose this for certain without a copy of your data file 'box.txt'. Can you attach it here?

    In case it helps, let me try to clarify what command you show implies about the data file. The fourth field in the using specifier refers to a column in the input file. In your first command you have asked it to look for category strings in a column of the input file with columnheader "A". In the second command you have asked it to look for category strings in a column with columnheader "B". Is that how your input file is structured?

     
  • Hiroki Motoyoshi

    I'm not the original poster, but I was able to reproduce the issue.

    In the following script:

    $data <<EOD
    1  1
    2  8
    3  6
    4  6
    5  5
    6  8
    7  9
    8  7
    9  6
    10 5
    
    1  4
    2  3
    3  4
    4  5
    5  6
    6  6
    7  7
    8  2
    9  3
    10 5
    EOD
    
    set yrange [0:*]
    set offset 0,0,1,1
    unset key
    
    plot $data using (1):2:(0.5):("A") every :::0::0 with boxplot, \
         $data using (2):2:(0.5):("B") every :::1::1 with boxplot
    
    pause -1
    
    set xrange [-1000:3]
    replot 
    pause -1
    

    Label "A" is placed correctly, but label "B" is placed at x = -999 instead of its expected position. This can be confirmed by setting "xrange [-1000:3]".

    This happens because when using "every :::1::1", the first element in plot->points is a blank line, and plot->points[0].x is -999. Similarly, in the case of "every :::2::2", the first two elements are stored as blank lines, and for "every :::3::3", the first three elements become blank lines. These blank lines are assigned the point type UNDEFINED. However, since "add_tics_boxplot_factors()" does not detect whether the first element is UNDEFINED, it mistakenly assigns the x-axis value of -999, which causes the function to fail.

    The attached patch works around this by:
    - Using the explicit x value passed to "check_or_add_boxplot_factor()" for new_label->place.x.
    - Referring to label->place.x instead of plot->points->x in "add_tics_boxplot_factors()".

    With this change, labels are drawn at the correct positions even when using "every" with boxplots data.

     
  • Ethan Merritt

    Ethan Merritt - 2025-04-24

    Huh. I see what your patch is doing, but I am not sure that is really the issue here. It depends on what the original poster was actually aiming for.

    The fourth field of the boxplot "using" specifier is intended to be a column identifier, not a label. Are you assuming the original intent was this command?

    plot $data using (1):2:(0.5):xticlabel("A") every :::0::0 with boxplot, \
         $data using (2):2:(0.5):xticlabel("B") every :::1::1 with boxplot
    

    That indeed uncovers a bug, which can be worked around by using instead

    set boxwidth 0.5
    plot $data using (1):2:xticlabel("A") every :::0::0 with boxplot, \
         $data using (2):2:xticlabel("B") every :::1::1 with boxplot
    

    That bug is a curious one that only affected 4-column boxplots with tic labels. Fixed now..

    Your patch addresses a different case that may or may not be closer to the original intent. See test cases below. I have added your fix also (with a minor change to make the C compiler happy).

    $data <<EOD
    X  Y  A  B
    1  1  ZZ  e
    2  8  Q f
    f  6  ZZ  g
    4  6  Q e
    5  5  Q f
    6  8  ZZ  g
    7  9  Q e
    8  7  Q f
    9  6  ZZ  g
    10 5  Q e
    
    X  Y  A  B
    1  4  Q f
    2  3  Q g
    3  4  ZZ  e
    4  5  Q f
    5  6  Q g
    6  6  ZZ  e
    7  7  ZZ  f
    8  2  ZZ  g
    9  3  ZZ  e
    10 5  Q f
    EOD
    
    set datafile columnhead
    set yrange [0:*]
    set offset 0,0,1,1
    unset key
    
    plot $data using (1):2:(0.5):xticlabel("A") every :::0::0 with boxplot, \
         $data using (4):2:(0.5):xticlabel("B") every :::1::1 with boxplot
    
    pause -1
    
    plot $data using (1):2:(0.5):3 every :::0::0 with boxplot, \
         $data using (4):2:(0.5):4 every :::1::1 with boxplot
    
    pause -1
    
    plot $data using (1):2:(0.5):"A" every :::0::0 with boxplot, \
         $data using (4):2:(0.5):"B" every :::1::1 with boxplot
    
     
    • Hiroki Motoyoshi

      Actually, I had assumed that the original poster's syntax should work as intended. This is because the "help boxplot" documentation contains the following description regarding x-axis labels:

      You can place an identifying label at this position under the boxplot by adding an xticlabel specifier in the plot command (two or three column syntax) or by providing it as a string in a separate data column (four column syntax).

      While the latter part of the documentation mentions that the fourth field can also act as a column selector, the straightforward reading of the sentence above suggests that in the four-column syntax, the label is expected to be a string provided directly in the fourth column—not specified via xticlabel.

      In fact, when not using every, the syntax with a string label in the fourth column does behave that way.

      Also, commit 8a06321e826b6a89b3d0468e8d4e314575d66ab8 says:

      Allow 'using xticlabel(<foo>)' for style 'with boxplot'
      Not strictly necessary, since using (x):(data):(width):(<foo>) does the same thing. But people are more likely to think of this first.</foo></foo>

      This implies that the syntax used by the original poster is also considered valid, or at least acceptable.

      In any case, it's hard to be certain without seeing the contents of 'box.txt'. That would help clarify what the intended syntax was and whether the fourth field was meant to be a label or a column index.

       
      • Ethan Merritt

        Ethan Merritt - 2025-04-24

        I took the intended meaning of the documentation sentence you quote to be

        You can place an identifying label at this position under the boxplot by adding an xticlabel specifier in the plot command (two or three column syntax) or by providing labels in a fourth column of the data file (four column syntax).

        But I can totally see how providing a string constant in parentheses would seem like it would substitute for a real fourth column just the way providing a numerical constant in parentheses substitutes for numerical values in a real data column.

        Anyhow, that's two fixes for two real bugs. Hopefully one or the other solves the original problem.

         
        • Hiroki Motoyoshi

          But I can totally see how providing a string constant in parentheses would seem like it would substitute for a real fourth column just the way providing a numerical constant in parentheses substitutes for numerical values in a real data column.

          Your explanation really cleared things up for me. In a plot command such as:

          plot $data using (1):2:(0.5):("A") with boxplot
          

          the fourth column, ("A"), can be interpreted as indicating that every record belongs to the category (or factor) "A".

          Anyhow, that's two fixes for two real bugs. Hopefully one or the other solves the original problem.

          I hope so too.

           
  • Ethan Merritt

    Ethan Merritt - 2025-04-25
    • status: open --> pending-fixed
    • Group: -->
    • Priority: -->
     
  • Ethan Merritt

    Ethan Merritt - 2025-06-04
    • Status: pending-fixed --> closed-fixed
     

Log in to post a comment.