Prob. 8, Sec. 26, in Munkres' TOPOLOGY, 2nd ed: A map into a compact Hausdorff space is continuous iff its graph is closed Here is Prob. 8, Sec. 26, in the book Topology by James R. Munkres, 2nd edition: 

Theorem. Let $f \colon X \to Y$; let $Y$ be compact Hausdorff. Then $f$ is continuous if and only if the graph of $f$, 
  $$ G_f = \{ \ x \times f(x) \ \vert \ x \in X \ \}, $$
  is closed in $X \times Y$. [Hint: If $G_f$ is closed and $V$ is a neighborhood of $f \left( x_0 \right)$, then the intersection of $G_f$ and $X \times (Y-V)$ is closed. Apply Exercise 7.] 

And, here is Prob. 7, Sec. 26, in Munkres' Topology, 2nd edition: 

Show that if $Y$ is compact, then the projection $\pi_1 \colon X \times Y \to X$ is a closed map. 

Here is a solution to this problem.
My Attempt: 
I think I can slightly generalize Prob. 8, Sec. 26, in Munkres as follows: 

Let $X$ and $Y$ be topological spaces, and let $f \colon X \to Y$ be a function. 
(a) If $Y$ is Hausdorff and if $f$ is continuous, then the graph $G_f$ of $f$ is a closed set in the product space $X \times Y$. 
(b) If $Y$ is compact and if the graph $G_f$ of $f$ is closed in the product space $X \times Y$, then the function $f$ is continuous. 

Am I right? 
Proof (a): 

Suppose that $Y$ is a Hausdorff space, and suppose also that the map $f \colon X \to Y$ is continuous. We need to show that the graph $G_f$ of $f$ is closed in the product space   $X \times Y$. For this we show that $(X \times Y) - G_f$ is open in $X \times Y$.
Let $x_0 \times y_0$ be a point of $X \times Y$ such that $x_0 \times y_0 \not\in G_f$. Then $x_0 \in X$, $y_0 \in Y$, but $f \left( x_0 \right) \neq y_0$. Thus $f \left( x_0 \right)$ and $y_0$ are two distinct points in the Hausdorff space $Y$. So there exist open sets $U_0$ and $V_0$ in $Y$ such that 
  $$ f \left( x_0 \right) \in U_0, \qquad y_0 \in V_0, \qquad \mbox{ and } \qquad U_0 \cap V_0 = \emptyset. \tag{1} $$
  As $f \left( x_0 \right) \in U_0$, so $x_0 \in f^{-1} \left( U_0 \right)$, where 
  $$ f^{-1} \left( U_0 \right) \colon= \left\{ \ x \in X \ \colon \ f(x) \in U_0 \ \right\}. $$
  And, as $U_0$ is an open set in $Y$ and as $f \colon X \to Y$ is continuous, so the set $f^{-1} \left( U_0 \right)$ is an open set in $X$. Thus $f^{-1} \left( U_0 \right)$ is a neighborhood of $x_0$ in $X$. 
As $x_0 \in f^{-1} \left( U_0 \right)$ and as $y_0 \in V_0$ [Refer to (1) above.], so we can conclude that  $x_0 \times y_0 \in f^{-1} \left( U_0 \right) \times V_0$. 
And, as $f^{-1} \left( U_0 \right)$ is open in $X$ and $V_0$ is open in $Y$, so $f^{-1} \left( U_0 \right) \times V_0$ is open in $X \times Y$; in fact, the set $f^{-1} \left( U_0 \right) \times V_0$ is a basis element for the product topology on $X \times Y$. 
We now show that 
  $$ f^{-1} \left( U_0 \right) \times V_0 \ \subset \ \big(X \times Y \big) - G_f.$$
For this, let $x \times y$ be any point in the set $f^{-1} \left( U_0 \right) \times V_0$. Then $x \in f^{-1} \left( U_0 \right)$ and $y \in V_0$, and so $x \in X$ such that $f(x) \in U_0$ and $y \in V_0$. 
Now as $f(x) \in U_0$ and $y \in V_0$ and as $U_0 \cap V_0 = \emptyset$ [Refer to (1) above.], so $f(x) \neq y$, and thus $x \times y \not\in G_f$. But of course $x \times y \in X \times Y$. Thus $x \times y \in (X \times Y) - G_f$. 
Therefore we can conclude that 
  $$ f^{-1} \left( U_0 \right) \times V_0 \subset (X \times Y) - G_f. $$
Thus we have shown that, for every point $x_0 \times y_0$ in $(X \times Y) - G_f$, there exists a basis element $f^{-1} \left( U_0 \right) \times V_0$ for the product topology on $X \times Y$ such that 
  $$ x_0 \times y_0 \in f^{-1} \left( U_0 \right) \times V_0 \subset (X \times Y) - G_f. $$
  So the set $(X \times Y) - G_f$ is open in the product space $X \times Y$. Hence $G_f$ is closed in $X \times Y$. 

Is this proof correct and clear enough? 
Proof (b):

Suppose that $Y$ is compact, and suppose also that the graph $G_f$ of $f$ is closed in the product space $X \times Y$. We need to show that the map $f \colon X \to Y$ is continuous. For this we will have to show that the inverse image $f^{-1}(V)$ is open in $X$ for any open set $V$ in $Y$. 
Let $V$ be an open set in $Y$. If $f^{-1}(V)$ is empty, then it is trivially open in $X$. So we assume that $f^{-1}(V)$ is non-empty. 
As $V$ is open in $Y$, so $Y-V$ is closed in $Y$. And, as $X$ is closed in $X$ and $Y-V$ is closed in $Y$, so $X \times (Y-V)$ is closed in the product space $X \times Y$, by Prob. 3, Sec. 17, in Munkres, to which here is a solution.
Now as the graph $G_f$ of $f$ is closed in $X \times Y$ by our hypothesis and as $X \times (Y-V)$ is closed in $X \times Y$, so is the intersection $G_f \cap \big( X \times (Y-V) \big)$. 
But we note that 
  $$ 
\begin{align}
 G_f \bigcap \big( X \times (Y-V) \big) &= \{\  x \times y \in X \times Y \ \colon \ y = f(x), \ y \not\in V \ \} \\
& = \{ \ x \times f(x) \ \colon \ x \in X, \ f(x) \not\in V \ \}.  \end{align} \tag{2} $$
Now as the topological space $Y$ is compact, so the projection map $\pi_1 \colon X \times Y \to X$, defined by 
  $$ \pi_1(x\times y) \colon= x \ \mbox{ for all } x \times y \in X \times Y, \tag{3} $$
  is a closed map, by Prob. 7, Sec. 26.
And, as the set $G_f \bigcap \big( X \times (Y-V) \big)$ is closed in the product space $X \times Y$ and as the projection map $\pi_1 \colon X \times Y \to X$, defined by (3) above is a closed map, so the set 
  $$ \pi_1 \left( G_f \bigcap \big( X \times (Y-V) \big)  \right) \colon= \left\{ \ \pi_1 (x \times y) \ \colon \ x \times y \in G_f \bigcap \big( X \times (Y-V) \big) \ \right\}$$
  is a closed set in the topological space $X$. 
But using the definition of the map $\pi_1$ in (3) above we can write 
  $$ \pi_1 \left( G_f \bigcap \big( X \times (Y-V) \big)  \right)   = \left\{ \ x \in X \ \colon \ x \times y \in G_f \bigcap \big( X \times (Y-V) \big) \mbox{ for some } y \in Y \ \right\}. \tag{4} $$
Thus from (2) and (4) above we can conclude that 
  $$ \pi_1 \left( G_f \bigcap \big( X \times (Y-V) \big)  \right) = \{ \ x \in X \ \colon \ f(x) \not\in V \ \} = X - f^{-1}(V), $$
  using the familiar properties of the inverse images of subsets of the range / codomain of a map between sets. 
Thus we can conclude that $X - f^{-1}(V)$ is closed in $X$, which implies that $V$ is open in $X$, as required. 

Is this proof correct and clear enough also?
Are both parts of my proof correct in each and every step? If so, then is it clearly worded and neatly arranged too? If not, then where are the issues? 
This and this are a couple of posts of mine here on Mathematics Stack Exchange on a similar problem. 
 A: Both your statements and their proofs in themselves are fine. But they could be a lot shorter:
a) $F: X \times Y \to Y \times Y$, defined by $F(x,y) = (f(x), y)$ is continuous by the characterisation of maps into products: $\pi_1 \circ F = f$ and $\pi_2 \circ F = \textrm{id}_Y$ for the two projections from $Y \times Y$ onto its factors, and both are continuous, hence so is $F$.
$Y$ Hausdorff is equivalent to $\Delta_Y \subseteq Y \times Y$ being closed. (IIRC this is also an exercise in Munkres).
Hence for Hausdorff $Y$ (compact not needed) and continuous $f$ we have that $G_f = F^{-1}[\Delta_Y]$ is closed in $X \times Y$, being the inverse of a closed set under a continuous map.
b) If $Y$ is compact (Hausdorff not needed for this direction), the projection $\pi_X: X \times Y \to X$ is a closed function (as you also used in the proof). 
If $C \subseteq Y$ is closed, it suffices to note that $$f^{-1}[C] = \pi_X[(X \times C) \cap G_f]$$ (easily shown by showing two inclusions: $x \in f^{-1}[C]$ iff $f(x) \in C$ and then $x = \pi(x,f(x))$ and $(x,f(x)) \in G_f \cap (X \times C)$ etc.) and so when $G_f$ is closed, so is $f^{-1}[C]$ for all closed subsets of $Y$, hence $f$ is continuous.
The essence of this idea is already in your proof, but you can go to the core right away. Also use the inverse image of closed sets for continuity, as the condition is in terms of closedness.
