I am trying to create a density plot with TikZ using \fill and tightly stacked rectangles. The thin unwanted borders in the image, are they an artefact of rendering or a feature of fill? Can they be eliminated/smoothened?

\usepackage{gnuplot-lua-tikz}   %for colors
\fill[rgb color={0.40,0.50,0.01}, opacity=0.75] (0.000,0.00) -- (2.000,0.00) -- (2.000,0.40) -- (0.000,0.40) -- cycle;
\fill[rgb color={0.40,0.50,0.01}, opacity=0.75] (0.000,0.40) -- (2.000,0.40) -- (2.000,0.80) -- (0.000,0.80) -- cycle;
\fill[rgb color={0.40,0.50,0.01}, opacity=0.75] (0.000,0.80) -- (2.000,0.80) -- (2.000,1.20) -- (0.000,1.20) -- cycle;
\fill[rgb color={0.40,0.50,0.01}, opacity=0.75] (0.000,1.20) -- (2.000,1.20) -- (2.000,1.60) -- (0.000,1.60) -- cycle;
\fill[rgb color={0.40,0.50,0.01}, opacity=0.75] (0.000,1.60) -- (2.000,1.60) -- (2.000,2.00) -- (0.000,2.00) -- cycle;
\fill[rgb color={0.68,0.74,0.48}, opacity=0.75] (0.000,2.00) -- (2.000,2.00) -- (2.000,2.40) -- (0.000,2.40) -- cycle;
\fill[rgb color={0.95,0.96,0.92}, opacity=0.75] (0.000,2.40) -- (2.000,2.40) -- (2.000,2.80) -- (0.000,2.80) -- cycle;
\fill[rgb color={0.99,0.99,0.98}, opacity=0.75] (0.000,2.80) -- (2.000,2.80) -- (2.000,3.20) -- (0.000,3.20) -- cycle;
% ...

zoom image

enter image description here

  • 1
    Welcome to TeX.SX! I would guess a rendering issue, but I cannot say for certain, and I cannot compile your example either. gnuplot-lua-tikz is not on CTAN, so it would be nice if you added a link. But even if I use the one that is the first hit on Google, I get an error because the rgb color key isn't defined there, or in TikZ. Mar 21, 2014 at 9:26
  • Thank you! I thought I fixed the color issue but apparently it does not work for everyone. I will try to find a workaround and get back to you with my question soon. Thanks again.
    – user43791
    Mar 21, 2014 at 9:33
  • 1
    Not sure why but it appears that there are lines being draw. You could try the option line width=0pt -- just a wild guess though. Mar 21, 2014 at 9:42
  • Just tested you example by replacing the rgb color with different shades of green, and I didn't get any white lines. Try zooming in/out a bit in the PDF viewer. Mar 21, 2014 at 10:42
  • You can try draw, line width=0.5pt (or any suitable dimension), generally speaking, that assures that rectangles are slightly bigger and they are covering some extra (hopefully white) space around the border.
    – Malipivo
    Mar 21, 2014 at 21:31

1 Answer 1


I think it is an artefact of the PDF reader. I get white lines in evince and dark lines in AR9/Linux, both depending on the view scale.

If the border line of the fill area does not lie on a pixel border, then the PDF viewer has to decide, how to colorize these border pixels. Then in evince they are left blank, and in AR they get color from both fill areas (opacity=75).

Therefore I would use a bitmap image instead. Example, your first image has 26 columns. After scaling it in gimp to width 26 pixels I get an image with 26 x 37 pixels: xUnJo.png

In the TeX document the image is scaled up again, e.g.:





The file in the question uses opacity=0.75. There are two ways to support this using bitmaps:

  • PNG supports transparency by an alpha channel.
  • The bitmap can be created without transparency (also the file size should be smaller without alpha channel). And the transparency is added, when the image is included.

Bitmap generation

  • Direct approach.

    The color values are directly written into the image file. Portable PixMap is an easy format, because it knows an ASCII version. Example for the MWE:

    # The P3 means RGB colors in ASCII.
    # Next line: 1 row, 9 columns (from bottom to top)
    # Following line: max. color
    # Then image data as integers.
    1 9
    252 252 250
    242 245 235
    173 189 122
    173 189 122
    102 127 3
    102 127 3
    102 127 3
    102 127 3
    102 127 3

    Then the image can be converted to PNG, e.g. with pnmtopng of the Netpbm tools:

    pnmtopng <myimage.ppm >myimage.png
  • Indirect approach.

    The tikzpicture goes into a separate page/document without margins. Then the PDF version can be converted to an image with the number of columns/rows as pixel width/height. Conversion example with ImageMagick and an image with 26 columns and 37 rows:

    convert -resize 26x37 myimage.pdf myimage.png

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .