Let $X$ be a $T_2$ space .Let $f:X\rightarrow \mathbb R$ be such that $\{(x,f(x):x\in X\}$ is compact.Show that $f$ is continuous
My attempt:
Let $x_n$ be a sequence in $X$ converging to $x$.To show $f$ is continuous we have to show $f(x_n)\rightarrow f(x)$ .Consider $\{(x_n,f(x_n)\}$ which is a compact subset of $X\times \mathbb R$ (Since $X$ and $\mathbb R$ both are $T_2$ so is $X\times \mathbb R$) and hence closed.Thus contains all its limit points.$\{(x_n,f(x_n)\}$ has a convergent subsequence say$\{(x_{n_k},f(x_{n_k})\}$ converging to $(x,y')$(limit is unique since $X$ is $T_2$).Am I proceeding correctly.How to show from here $f(x_n)\rightarrow f(x)$?
Without sequences or nets: let $G(f) = \{(x,f(x): x \in X \}$. To show continuity, it suffices to show that for a closed $F \subset \mathbb{R}$, the set $f^{-1}[F]$ is closed. So assume we have such $F$.
The function $\pi_1: X \times \mathbb{R}, \pi_1(x,y) = x$, is continuous.
The key thing to see is: $$f^{-1}[F] = \pi_1[G(f) \cap (X \times F)]$$
(If $x \in f^{-1}[F]$, then $f(x) \in F$, so $(x,f(x)) \in G(f)$ and also $(x,f(x)) \in X \times F$, and $x = \pi_1(x,f(x))$ is in the right hand side. If $x$ is in the right hand side, there exists, for some $y$, $(x,y) \in G(f) \cap (X \times F)$. But being in $G(f)$ forces $y = f(x)$ and as $y = f(x) \in M$, $x \in f^{-1}[F]$.)
The right hand side is the continuous image of a compact set (the intersection of a closed set $X \times F$ and the compact $G(f)$) so is compact. And as $X$ is Hausdorff, $f^{-1}[F]$ is closed, as required.