TITLE: The underlying space of a scheme remembers its affineness?
QUESTION [6 upvotes]: Let $f:X\rightarrow Y$ be a morphism of schemes. We know that if $Y$ is affine and $f$ induces homeomorphism on the underlying spaces then $X$ is affine. Is it true that if $X$ is affine and $f$ induces a homeomorphism on the underlying spaces then $Y$ is affine? 
More generally, is it true that a scheme whose underlying space is homeomorphic (possibly via a homeomorphism that is not induced by a morphism of schemes) to the underlying space of an affine scheme is affine? EDIT: actually, the answer to the last question is a very strong "NO" as the underlying space of any scheme is sober and Noetherian sober spaces are spectral (i.e. homeomorphic to the underlying space of an affine scheme).

REPLY [5 votes]: As pointed out by abx here, the following example fits the bill.
Take a nodal cubic in $\mathbb{P}^2$, this is an irreducible scheme proper over $\mathbb{C}$, take its normalization and throw out a point from the inverse image of the node. We get a $\mathbb{C}$-morphism from the affine line to our cubic, which is bijective on the underlying spaces. Since a non-empty proper closed subspace of either the affine line or the cubic is a finite union of closed points, this morphism is also closed, thus it induces a homeomorphism on the underlying spaces. I find it somewhat amusing that this example was not pointed out earlier (indeed, it seems to be even simpler than Julian Rosen's much upvoted example).