What is a standard way to make 2D region plots from data, using pgfplots? I've searched the forum, but I haven't found a thread on this subject.

The data would be organized, for example, in a three columns CSV, representing a 3D surface.

Probably one could start filling with colors the regions between contours in a "contour plot". But I would like an automatic way that works fine even when there are multiple separated regions that should have the same color.

The perfect example of what I would like is the figure, shown below for completness, from this Mathematica.SX thread. Please ignore the logscale, title and labels, because obviously the present question is not about such details; except that a similar legend would be welcome.


Additionally, is it possible to have control over colors, using maybe a piecewise function, similarly to what it is asked in the above Mathematica thread?


A very simple example, would be the paraboloid-like surface found in here, as a CSV.

  • Can you provide some dummy data in the form of a MWE? No need to make it compilable as it is the reason for the question anyway but the general axis environment, document class etc.
    – percusse
    Jul 3, 2013 at 12:27
  • 1
    Because it's not fun and also effort doubling if I understand something and you are looking for something else. You can check other pgfplots questions for examples of MWEs.
    – percusse
    Jul 3, 2013 at 12:50
  • 2
    To create a contour plot from gridded data, you can use the approach from tex.stackexchange.com/questions/65507/3d-surface-plots-in-tikz, with view={0}{90} in the axis options. For interpolating scattered data, look at tex.stackexchange.com/questions/118131/….
    – Jake
    Jul 3, 2013 at 12:54
  • 1
    @fcpenha: A region plot is just a surface plot viewed directly from above. The questions I linked to show how to create surface plots from data, they don't show how to create contour plots.
    – Jake
    Jul 3, 2013 at 14:41
  • 3
    Your image appears to belong to a filled contour plot. Pgfplots comes without support for filled contour plots (although these would be handy here). The alternatives offered by pgfplots have been discussed by others here. One further alternative generate a filled contour plot with an external tool and include it by means of \addplot graphics. Or to explain to me how the algorithm for non-filled contours can be reused to implement filled contours (I would consider an implementation). Jul 3, 2013 at 16:15

1 Answer 1


EDIT Starting with pgfplots 1.14, you can draw such figures by means of the new contour filled






    \begin{axis}[colorbar, view={0}{90}]
    \addplot3[domain=0:2*pi,trig format plots=rad,
        patch type=bilinear,
        contour filled={


enter image description here

The example is taken from the manual (combined with patch type=bilinear for improved quality). The example shows how to choose the levels explicitly; but the manual also explains how to merely use number or more advanted mappings. The colorbar comes with default settings.

Your image appears to belong to a filled contour plot.

Pgfplots comes without support for filled contour plots (although these would be handy here).

The alternatives offered by pgfplots are: you can either use a surface plot (although these tend to look pixelated when viewed from above) or you can accept that pgfplots cannot do it by means of builtin methods and import the stuff as .png graphics.

The second alternative is a way to extend the capabilities of pgfplots beyond its own limitations: you can generate the graphics (without axis) with an external tool, import it using \addplot graphics and pgfplots will automatically integrate it into your figure.

A third alternative might be to explain to the package author of pgfplots (that happens to be me) how to extend the existing contour plot handlers to support filling. This would need to be done by email (there are already limited approaches in pgfplots which could be continued).

A fourth alternative is to give up consistency and use a completely different tool, for example by importing your example graphics directly.

  • Great! You have helped me a lot. Thank you very much for organizing the ideas from the discussion. Cheers.
    – fcpenha
    Jul 9, 2013 at 3:18

You must log in to answer this question.

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