10

I would like to draw a graphic, where “colorfulness” corresponds with some value. (Say, e. g. a map, where the more people live in an area, the “reder” this area gets.)

I now stumbled across the way TikZ handles transparencies. As a MWE:

\documentclass{article}

\usepackage{tikz}

\begin{document}
 \begin{tikzpicture}
    \fill[red, fill opacity=1.000] (0,0) circle (1);
  \foreach \i in {1, 2, ..., 100}
    \fill[red, fill opacity=0.010] (2,0) circle (1);
  \foreach \i in {1, 2, ..., 1000}
    \fill[red, fill opacity=0.001] (4,0) circle (1);
 \end{tikzpicture}
\end{document}

(I just looped the overlapping to minimize the example. For real, I got multiple regions overlapping partially.)

I expected to get three circles that look all the same (filled red). Instead I get a red circle, a redish circle and no circle at all.

The redish case is a nuisance, but getting no circle leaves me wondering if there is a minimum value for transparency and how I can circumvent this restriction. If, say, the mimimum is 0.01, how can I overlap 101 circles and having them looking different than 100. (Given anyone can tell the difference on such a fine scale.)

  • 4
    Please consult the blend modes in the manual. This is a very technical behavior and gets handled by PostScript rather than TikZ measuring the opacities along the way. The last one is probably due to the viewer. And you only need one loop essentially. – percusse Aug 23 '16 at 13:38
  • Can't you use the value you are representing to specify the opacity directly? Why do you need a loop at all? If, say, there are 100 people for circle A, why not set the opacity to 100*\factor rather than creating 100 circles with opacity \factor? – cfr Aug 23 '16 at 22:55
1

The following might be wrong. But this is my best guess.

Usually a typical photo, generated by the camera on a mobile phone, consists of three color channels: red, green, and blue. Each channel has 8 bits. That is, the redness of a pixel lies between 0 (no red at all) and 255 (the reddest). So are greenness and blueness.

Since we know from experiments that human eyes cannot tell the difference between, say, 100-redness and 100.5-redness, we convince ourselves that we need only 256 rednesses.

Now look at opacity. Since there are only 256 rednesses, we do not need more than 256 opacities. We might also guess that during the calculation, a 0.49-opacity is going to be recorded as 0-opacity and 0.51-opacity is 1-opacity. The following code supports this guess.

\documentclass{article}
\usepackage{tikz}
\begin{document}
 \begin{tikzpicture}
  \foreach\i in{1,2,...,1000}\filldraw[fill opacity=1/508](0,0)circle (1);
  \foreach\i in{1,2,...,1000}\filldraw[fill opacity=1/509](2,0)circle (1);
 \end{tikzpicture}
\end{document}

Back to your question:

  • Theoretically they do not look the same. Overlapping 10000 circles of opacity 0.0001 is more likely to give you an opacity of 1-(1-0.0001)10000. The limit of this formula is 1-1/e, where e is the Euler's number.
  • Yes, there is a minimum value for transparency.
  • The difference is so tiny that it almost exceeds the limit of our eyes. Your readers are not going to notice the detail even if they actually can.
  • Besides, your screen, projector, or printer is not going to do the job since most of the devices support only 8-bit channel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.