4

I'm encountering unexpected behavior when using xbar interval or ybar interval plot styles with pgfplots.

When I use the option draw=none, I expect no border to appear around the bars, including in the legend. However, a border still appears in the legend (see the blue borders in the example below), even though it is suppressed in the plot itself.

Illustration of the blue borders

Looking for the definitions of the legend image code is not helping much...

/pgfplots/xbar interval legend/.style={ /pgfplots/legend image code/.code={ \draw [##1,/tikz/.cd,yshift=-0.2em,bar interval width=0.7,bar interval shift=0.5] plot coordinates {(0cm,0.8em) (5pt,0.6em) (10pt,0.6em)}; }, }, 

I don't know if I am missusing xbar interval or if it is a bug in pgfplots. Interestingly, adding draw opacity=0 does prevent the borders from showing up in the legend. Possibly related to Unexpected borders on legends of stacked bars in pgfplots.

Here is a MWE :

\documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \begin{document} \begin{tikzpicture} \begin{axis}[ybar interval, legend entries={A legend}] \addplot+[fill=red!50!white, draw=none, % draw opacity=0, ] coordinates {(0,2) (0.1,1) (0.3,0.5) (0.35,4) (0.5,3) (0.6,2) (0.7,1.5) (1,1.5)}; \end{axis} \end{tikzpicture} \end{document} 

1 Answer 1

3

It really seems to be a bug. The style of the legend image should actually be the same as the plot. But it seems that the stroke color is inverted, at least draw=none has no effect.

You could circumvent this using the following approach:

\documentclass{article} \usepackage{pgfplots} \pgfplotsset{compat=1.18} \makeatletter \pgfplotsset{ legend image hide stroke/.style={ legend image post style={draw={\tikz@fillcolor}} } } \makeatother \begin{document} \begin{tikzpicture} \begin{axis}[ybar interval, legend entries={A legend}] \addplot+[ fill=red!50!white, draw=none, legend image hide stroke, %draw opacity=0, ] coordinates {(0,2) (0.1,1) (0.3,0.5) (0.35,4) (0.5,3) (0.6,2) (0.7,1.5) (1,1.5)}; \end{axis} \end{tikzpicture} \end{document} 

output of above code

1
  • Maybe it has something to do with the settings via tikz/current plot style ... But I am unsure Commented Apr 24 at 17:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.