Real-valued function $f : \mathbb{R} \to \overline{\mathbb{R}}$ is continuous iff its graph is closed I'm considering functions  $f : \mathbb{R} \to \mathbb{R}$ with the codomain extended to the extended reals $\mathbb{R} \cup \{\pm\infty\}.$ Now if $f$ is continuous then the function $g : \mathbb{R} \times \overline{\mathbb{R}} \to \mathbb{R} : (x, y) \mapsto y - f(x)$ is also continuous. Then the graph of $f$ is the set $g^{-1}(\{0\})$ and is therefore closed.
It seems plausible that the converse is true - that is, that if the graph of $f : \mathbb{R} \to \overline{\mathbb{R}}$ is closed then $f$ is continuous - but I wouldn't be too surprised if there's an annoying counterexample.
Is the converse true?
 A: This is true. Given $[a,b] \subset \mathbb{R}$, $\mathrm{Gr}(f) \cap ([a,b] \times \overline{\mathbb{R}})$ is compact (since it is a closed set inside a compact one). It follows that $\pi_1 |_{\mathrm{Gr}(f) \cap ([a,b] \times \overline{\mathbb{R}})}$ is a homeomorphism with its image, and hence $f|_{[a,b]}=\pi_2 \circ (\pi_1 |_{\mathrm{Gr}(f) \cap ([a,b] \times \overline{\mathbb{R}})})^{-1}$ is continuous. Therefore $f|_{(a,b)}$ is continuous. Since this holds for arbitrary $(a,b) \subset \mathbb{R}$, $f$ is continuous in the whole real line.
Note that this generalizes to the following statement:

Let $X$ be locally compact and Hausdorff, and $Y$ be compact. If $f:X \to Y$ is a function such that $\mathrm{Gr}(f)$ is closed, then $f$ is continuous.

A: Suppose $f$ is not continuous at some $x_0$. Then there is a sequence $(x_n)$ with $x_n \to x_0$, but $|f(x_n) - f(x_0)|\geq \epsilon >0$ for all $n$.
Switching to a subsequence, we can assume $f(x_n)\to y \in \overline{\mathbb{R}}$, since $\overline{\mathbb{R}}$ is sequentially compact. Since th graph of $f$ is closed, this means $(x_0,y)\in \mathrm{graph} f$ and hence $y=f(x_0)$. Hence, (along the subsequence) $f(x_n)\to y =f(x_0)$, in contradiction to $|f(x_n) - f(x_0)|\geq \epsilon >0$ for all $n$.
