2

I want to draw the following diagram using pgfplot

enter image description here

But I am able to draw it upto this.

enter image description here

I will be glad if someone can help me complete this.

MWE

\documentclass[a4paper, 10pt]{report}
\usepackage{times}%times new roman
 \usepackage{bookmark}
 \usepackage[margin=0.5in]{geometry}
 \usepackage{multicol}
 \usepackage{pdflscape}
 \usepackage{blindtext}
 \usepackage{amsmath}
 \usepackage{amssymb} %% for drwaaaaaaaaaaaaaaaing special symbols
 \usepackage{empheq} %for box outside the equations
 %%%%% Script for griffiths
 % \usepackage{calligra}
 % \DeclareMathAlphabet{\mathcalligra}{T1}{calligra}{m}{n}
 % \DeclareFontShape{T1}{calligra}{m}{n}{<->s*[2.2]callig15}{}
 % \newcommand{\scripty}[1]{\ensuremath{\mathcalligra{#1}}}
 %%%%%%%%%%%%%%%%%
 %%%%%%%%%%%%% script for griffths 2
 \usepackage{calligra}
 \DeclareMathAlphabet{\mathcalligra}{T1}{calligra}{m}{n}
 \DeclareFontShape{T1}{calligra}{m}{n}{<->s*[2.2]callig15}{}
 \newcommand{\scriptr}{\mathcalligra{r}\,}
 \newcommand{\boldscriptr}{\pmb{\mathcalligra{r}}\,}
 %%%%%%%%%%%%%%%%%
 \usepackage{graphicx}
 \usepackage{graphics}
 %% for reducing list gap
 \usepackage{enumitem}
 \setlist[itemize]{noitemsep, nolistsep}
 \setlist[enumerate]{noitemsep,nolistsep}
 %%%%
 \usepackage{lscape} %%% used for making a landscape
 \usepackage{pgfplots}
 \usepackage{wrapfig}
 \usepackage{tikz}
 \usetikzlibrary{angles,quotes}
      \usetikzlibrary{arrows,arrows.meta,backgrounds,calc,decorations,decorations.markings,decorations.pathmorphing,fit,positioning,shapes.arrows,shapes.callouts,shapes.geometric,shapes.misc}
 \usepackage{circuitikz} %for drwaing ee circuit
 \usepackage [edges, linguistics]{forest} % for drawing forest
 \usepackage{pgfplots}
 \usepackage{authblk}
 \usepackage{minitoc} % toc inside chapter
 \usepackage{lipsum}
 \usepackage{hyperref}     %for hyperref in table of contents
 \hypersetup{
%linktocpage=true,
colorlinks=true,
linkcolor=blue,
filecolor=blue,      
urlcolor=blue,
citecolor=blue,
%bookmarks=true,
}
 \setcounter{tocdepth}{1}
 \setcounter{minitocdepth}{1}
 \usepackage{fancyhdr}
 \setlength{\columnseprule}{0.5pt}
 \begin{document}
 \begin{center}
 \begin{tikzpicture}[width=\columnwidth]

\begin{axis}[
  xlabel={$I_3$},
  ylabel={$Y$},
  xmin=-1.5, xmax=1.5,
  ymin=-1.5, ymax=1.5,
  xtick distance=0.5, %puts number at a unit distance
   ytick distance=1, %puts number at a unit distance
   xtick={-1, -0.5, 0.5, 1},
   xticklabels={$-1$, $-\dfrac{1}{2}$, $\dfrac{1}{2}$, $1$},      
  axis lines=middle,
  axis line style={->},      
  extra description/.code={
    \draw[fill=blue] (axis cs:0,0) circle (2pt);},     
  ]
  \addplot coordinates {
(1, 0)
(0.5, 1)
(-0.5, 1)
(-1, 0)
(-0.5, -1)
(0.5, -1)
(1,0)
 };
\addplot[
dashed,
line width=1pt,
mark=none
 ] coordinates {
(-0.5, 1)
(0.75, -1.5)
 };
\addplot[
dashed,
line width=1pt,
mark=none
 ] coordinates {
(0.5, 1)
(1, 1)
 };
\addplot[
dashed,
line width=1pt,
mark=none
 ] coordinates {
(1, 0)
(1.25, -0.5)
 };
\addplot[
dashed,
line width=1pt,
mark=none
 ] coordinates {
(-0.5, -1)
(-0.25, -1.5)
 };
\addplot[
dashed,
line width=1pt,
mark=none
 ] coordinates {
(0.5, -1)
(1, -1)
 };
\end{axis}
   \end{tikzpicture}
 \end{center}
 \end{document}
4
  • 1
    Thanks for the code. May I ask you to prune it a little bit more? E.g. blindtext is not needed for this drawing. Just the basic neccessities, which still do compile after copy. // Suggestion: Consider using polar coordinates, like (0:1), (60:1), 12:1) etc.
    – MS-SPO
    Commented Jun 3, 2023 at 14:52
  • 1
    @ MS-PRO I have pruned it. This code is actually a part of a whole document. So, you can see many packages which may not be relevant for drawing this. Commented Jun 3, 2023 at 15:50
  • Thank you. Still obscure. Why do you use pgfplot here?
    – MS-SPO
    Commented Jun 3, 2023 at 15:55
  • 1
    @MS-SPO For drawing the two axes. Y and I_3 Commented Jun 3, 2023 at 15:57

2 Answers 2

3

I'd draw the axes myself and then it's just some nodes and edges.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs, quotes}
\tikzset{
  x tick/.pic={\draw[-,gray] (down:3pt)
    node[black, below, style/.expand once=\tikzpictextoptions]
      {$\displaystyle\tikzpictext$} -- (up:3pt);},
  y tick/.pic={\draw[-,gray] (left:3pt)
    node[black,  left, style/.expand once=\tikzpictextoptions]
      {$\displaystyle\tikzpictext$} -- (right:3pt);}}
\begin{document}
\begin{tikzpicture}[
  x = 2.5cm, y = 2.5cm,
  dot/.style={circle, inner sep=+1.25pt, draw, fill, blue},
  axis/.style={draw, ->, behind path}]
\draw[axis] (left:1.5) -- (right:1.75) node[above left]{$I_3$}
  pic foreach \v/\t in {-1, -.5/-\frac12, .5/\frac12, 1} ["\t"] at (\v,0) {x tick};
\draw[axis] (down:1.5) -- (up:1.5) node[below right]{$Y$}
  pic foreach \v in {-1, 1} ["\v"] at (0,\v) {y tick};

\node[dot, "$d$" above right,
           "$e$" below  left] (d0) at ( 0  , 0) {};
\node[dot, "$f$" above right] (d1) at ( 1  , 0) {};
\node[dot, "$b$" above      ] (d2) at (  .5, 1) {};
\node[dot, "$a$" above  left] (d3) at (- .5, 1) {};
\node[dot, "$c$" above  left] (d4) at (-1  , 0) {};
\node[dot, "$g$" below  left] (d5) at (- .5,-1) {};
\node[dot, "$h$" below  left] (d6) at (  .5,-1) {};
\path[blue] graph[use existing nodes, cycle] {\foreach\i in {1,...,6}{d\i}};
\path[dashed, thick, at end]
  (d3) edge (d0)
  (d0) edge (d6)
  (d6) edge["$S=-1$"       right] +(right:.5)
       edge["$Q= 0$" below right] +(.25,-.5)
  (d5) edge["$Q=-1$" below right] +(.25,-.5)
  (d1) edge["$Q= 1$" below right] +(.25,-.5)
       edge["$S= 0$" below      ] +(right:.5)
  (d2) edge["$S= 1$"       right] +(right:.5)
;
\end{tikzpicture}
\end{document}

Output

enter image description here

3

Here is a tikz-way to do it, with some room left for improvement. Main points:

  • defined a style for circles: crc/.style={radius=.5mm,fill=blue}
  • the axes do: draw from here to there, put at least one (text) node within the same path, shifting the text as needed \draw[->] (0,-2.2) -- (0,2.2) node[xshift=2mm]{Y};
  • same idea for the octet, diagonals, horizontals: just a long path, putting some circles and some text-nodes; we don't need to remember coordinates as they are obvious here
  • for the ticks, move to the starting point and find 2 relative positions from there (the +) \draw (-.5,0) -- +(0,-3pt) -- +(0,3pt);
  • finally put the missing values for the axes: \node at (-1,-4mm) {$-1$};

For some reason I didn't find out why point c etc. are somewhat skewed; so the polar-angle wasn't -60, but -63 deg.

The drawing is rather cramped. Some options:

  • recalculate the coordinates manually
  • use scaling via calc (gives even more code)
  • use smaller text, either via tikz-option or directly using \small etc inside the {text}
  • use a combination of these options
  • PLUS ... see P.S. below (!)

You could add the same parts for S, Q etc. to your diagram, but need to take care about some specific rules. See the pgfplot manual about interaction with tikz.

new and original result compared

\documentclass[10pt,border=3mm,tikz]{standalone}
% \documentclass[a4paper, 10pt]{report}

%\usepackage{times}%times new roman
% \usepackage{bookmark}
% \usepackage[margin=0.5in]{geometry}
% \usepackage{multicol}
% \usepackage{pdflscape}
% \usepackage{blindtext}
% \usepackage{amsmath}
% \usepackage{amssymb} %% for drwaaaaaaaaaaaaaaaing special symbols
 \usepackage{empheq} %for box outside the equations
 %%%%% Script for griffiths
 % \usepackage{calligra}
 % \DeclareMathAlphabet{\mathcalligra}{T1}{calligra}{m}{n}
 % \DeclareFontShape{T1}{calligra}{m}{n}{<->s*[2.2]callig15}{}
 % \newcommand{\scripty}[1]{\ensuremath{\mathcalligra{#1}}}
 %%%%%%%%%%%%%%%%%
 %%%%%%%%%%%%% script for griffths 2
% \usepackage{calligra}
% \DeclareMathAlphabet{\mathcalligra}{T1}{calligra}{m}{n}
% \DeclareFontShape{T1}{calligra}{m}{n}{<->s*[2.2]callig15}{}
% \newcommand{\scriptr}{\mathcalligra{r}\,}
% \newcommand{\boldscriptr}{\pmb{\mathcalligra{r}}\,}
% %%%%%%%%%%%%%%%%%
% \usepackage{graphicx}
% \usepackage{graphics}
% %% for reducing list gap
% \usepackage{enumitem}
% \setlist[itemize]{noitemsep, nolistsep}
% \setlist[enumerate]{noitemsep,nolistsep}
% %%%%
% \usepackage{lscape} %%% used for making a landscape
 \usepackage{pgfplots}
% \usepackage{wrapfig}
 \usepackage{tikz}
 \usetikzlibrary{angles,quotes}
      \usetikzlibrary{arrows,arrows.meta,backgrounds,calc,decorations,decorations.markings,decorations.pathmorphing,fit,positioning,shapes.arrows,shapes.callouts,shapes.geometric,shapes.misc}
% \usepackage{circuitikz} %for drwaing ee circuit
% \usepackage [edges, linguistics]{forest} % for drawing forest
% \usepackage{pgfplots}
% \usepackage{authblk}
% \usepackage{minitoc} % toc inside chapter
% \usepackage{lipsum}
% \usepackage{hyperref}     %for hyperref in table of contents
% \hypersetup{
%%linktocpage=true,
%colorlinks=true,
%linkcolor=blue,
%filecolor=blue,      
%urlcolor=blue,
%citecolor=blue,
%%bookmarks=true,
%}
% \setcounter{tocdepth}{1}
% \setcounter{minitocdepth}{1}
% \usepackage{fancyhdr}
% \setlength{\columnseprule}{0.5pt}
\begin{document}
 
 \begin{tikzpicture}[
        crc/.style={radius=.5mm,fill=blue}
    ]
    % ~~~ axes ~~~~~~~~~~~
    \draw[->] (-2.2,0) -- (2.2,0) 
                node[yshift=3mm] {$I_3$} node[yshift=-3mm] {$S=0$};
    \draw[->] (0,-2.2) -- (0,2.2) node[xshift=2mm]{Y};
    % ~~~ octet ~~~~~~~~~~~~
    \draw [crc,draw=blue] (-.5,1)  circle node[xshift=-3mm,yshift=3mm] {a} -- 
                ( .5,1)  circle node[yshift=3mm]             {b} -- 
                ( 1 , 0) circle node[xshift=1mm,yshift=3mm]  {f} --
                ( .5,-1) circle node[xshift=-1mm, yshift=-3mm] {h} -- 
                (-.5,-1) circle node[xshift=-3mm]           {g} -- 
                (-1 ,0)  circle node[yshift=3mm]            {c} --
                (-.5,1); ; 
    % ~~~ diagonals ~~~~~~~~~~~~~
    \draw[dashed] (-.5,1) -- ++(-63:3) 
                        node[xshift=4mm,yshift=-2mm] {$Q=0$};
    \draw[dashed] (-.5,-1) -- ++(-63:.7) 
                        node[xshift=-6mm,yshift=-2mm] {$Q=-1$};
    \draw[dashed] (1,0) -- ++(-63:.5) 
                        node[xshift=3mm,yshift=-2mm] {$Q=1$};
    % ~~~ horizontals ~~~~~~~~~~~~~
    \draw[dashed] (.5,1) -- ++(0.7,0) node[xshift=5mm] {$S=1$};
    \draw[dashed] (.5,-1) -- ++(0.7,0) node[xshift=7mm] {$S=-1$};
    % ~~~ text at origin ~~~~~~~~~~~
    \draw[crc] (0,0) circle node[xshift=2mm,yshift=2mm] {d}
                            node[xshift=-2mm,yshift=-2mm] {e};
    % ~~~ ticks ~~~~~~~~~~~~
    \draw (-.5,0) -- +(0,-3pt) -- +(0,3pt);
    \draw ( .5,0) -- +(0,-3pt) -- +(0,3pt);
    % ~~~ values ~~~~~~~~
    \node at (-1,-4mm) {$-1$};
    \node at (-.5,-4mm) {$-\frac{1}{2}$};
    \node at ( .5,-4mm) {$ \frac{1}{2}$};
    \node at ( 1,-4mm) {$ 1$};
    
    \node at (-2mm,1) {$1$};
    \node at (-2mm,-1) {$-1$};

 
 \end{tikzpicture}
 
 
 % ~~~ posted code ~~~~~~~~~~~~~
% \begin{center}
 \begin{tikzpicture}%[width=\columnwidth]

\begin{axis}[
      xlabel={$I_3$},
      ylabel={$Y$},
      xmin=-1.5, xmax=1.5,
      ymin=-1.5, ymax=1.5,
      xtick distance=0.5, %puts number at a unit distance
       ytick distance=1, %puts number at a unit distance
       xtick={-1, -0.5, 0.5, 1},
       xticklabels={$-1$, $-\dfrac{1}{2}$, $\dfrac{1}{2}$, $1$},      
      axis lines=middle,
      axis line style={->},      
      extra description/.code={
        \draw[fill=blue] (axis cs:0,0) circle (2pt);},     
  ]
  \addplot coordinates {
    (1, 0)
    (0.5, 1)
    (-0.5, 1)
    (-1, 0)
    (-0.5, -1)
    (0.5, -1)
    (1,0)
  };
     
  \addplot[
    dashed,
    line width=1pt,
    mark=none
     ] coordinates {
    (-0.5, 1)
    (0.75, -1.5)
 };
\addplot[
    dashed,
    line width=1pt,
    mark=none
     ] coordinates {
    (0.5, 1)
    (1, 1)
     };
\addplot[
    dashed,
    line width=1pt,
    mark=none
     ] coordinates {
    (1, 0)
    (1.25, -0.5)
 };
\addplot[
    dashed,
    line width=1pt,
    mark=none
     ] coordinates {
    (-0.5, -1)
    (-0.25, -1.5)
 };
\addplot[
    dashed,
    line width=1pt,
    mark=none
     ] coordinates {
    (0.5, -1)
    (1, -1)
 };
\end{axis}
   \end{tikzpicture}
% \end{center}
\end{document}

P.S.: Looking at Qrrbrbirlbel's solution at https://tex.stackexchange.com/a/687586/245790, there's an even simpler option:

  • \begin{tikzpicture}[x = 2.5cm, y = 2.5cm,% <<< crc/.style={radius= ...

Tikz-magic ...

result2

You must log in to answer this question.

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