1

I am trying to recreate the following image I made with Matplotlib in Tikz/pgfplots. python_plot

So far I have successfully recreated the following using a pgfplots 3d surface plot, but there is one problem: I am using explicit colouring as described here (and loading my data from a semicolon-separated CSV file generated in Python, the file can found here), but when I use the shader option flat, pgfplots applies smoothing between adjacent colours which is absolutely not what I want (the colours represent integer values). Is there any way to disable this behaviour in pgfplots? So far I have come up empty-handed. Any help would be appreciated! tikz_plot

MWE:

\documentclass{article}

% Import packages
\usepackage{tikz}
\usepackage{tikz-3dplot} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        axis line style={draw=none},
        axis equal image,
        ticks=none,
        view={20}{20},
        clip=false,
        width=120mm,
        xmin = -1,
        xmax = 1,
        ymin = -1,
        ymax = 1,
        zmin = -1,
        zmax = 1,
    ]
        % Sphere plot
        \addplot3 [surf, mesh/rows=30, mesh/color input=explicit, shader=flat] table [
            x=x, y=y, z=z, meta=c, col sep=semicolon, 
        ] {xyz_coords_c_vals_30_60.csv}; 
    \end{axis}
\end{tikzpicture}

\end{document}

1 Answer 1

2

Nevermind, I must be oblivious: I found out that there is an option shader=flat corner (thanks to this post). Solves all my problems.

Working MWE (add the xyz_coords_c_vals.csv from here and add it to the same directory/folder):

\documentclass{article}

% Import packages
\usepackage{tikz}
\usepackage{tikz-3dplot} 
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
    \begin{axis} [
        axis line style={draw=none},
        axis equal image,
        ticks=none,
        view={20}{20},
        clip=false,
        width=120mm,
        xmin = -1,
        xmax = 1,
        ymin = -1,
        ymax = 1,
        zmin = -1,
        zmax = 1,
    ]
        % Sphere plot
        \addplot3 [surf, mesh/rows=30, mesh/color input=explicit, shader=flat corner] table [
            x=x, y=y, z=z, meta=c, col sep=semicolon, 
        ] {xyz_coords_c_vals_30_60.csv}; 
    \end{axis}
\end{tikzpicture}

\end{document}
2
  • 1
    @cabohah you mean like this, or something else? Jul 17, 2023 at 19:51
  • 1
    Yes. Best would be to have really self containing code without the need for external links (which could become invalid in future). But in this case, it could be difficult to reduce the external csv-file to make it small enough to add it into the answer without loosing too much information. So IMHO it is OK now and therefore +1. Others may disagree. But I cannot speak for others.
    – cabohah
    Jul 18, 2023 at 10:07

You must log in to answer this question.

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