TITLE: $f(x,y)$ is such that partial derivative w.r.t $x$ is zero, but$ f$ still depends on $x$?
QUESTION [6 upvotes]: I have a problem where it seems like I should be able to visualize an answer, but I can't.  Perhaps I need to take a more formal approach.
"Let $A$ be a non-empty open convex subset of $\mathbb{R}^2$, and suppose that $f: A \rightarrow \mathbb{R}$ satisfies that $\frac{\partial f}{\partial x} = 0$ at all points in $A$.  Prove that there is a function $g$ of one variable such that $f(x,y) = g(y)$.  Show that this conclusion may fail if convexity is replaced by connectedness."
For the first part, maybe I can do something like the following:
When $A$ is convex, I can take any points $\boldsymbol{a_0}, \boldsymbol{a_1} \in A$, where $\boldsymbol{a_0} = (x_0, y_0), \boldsymbol{a_1} = (x_0 + h, y_0)$, and have the line segment connecting them be in $A$. 
Since $\frac{\partial f}{\partial x} = 0$ everywhere on this line segment, some mean value business shows that $f(\boldsymbol{a_0}) = f(\boldsymbol{a_1})$, regardless of the value of $h$.  Therefore, at any given $y=y_0$, $f$ does not depend on $x$, so $f(x,y) = g(y)$ only.
Obviously I used convexity of $A$ to show this, but I can't seem to find a counterexample that makes it fail when $A$ is connected but not convex.  If $A$ were not even not connected, so it was separable into disjoint open sets $A_1$ and $A_2$, it would be easy to see that $f$ could have different constant values w.r.t. $x$ in each separate region.  This separation could allow $f$ to depend on $x$ overall even though $\frac{\partial f}{\partial x} = 0$ where ever $f$ is defined.  
It's the connected but not convex case that's troublesome. The more I think about it, the less sensible it sounds. If we want to show that $f(x,y)$ is not just a function of $y$, we should be able to find some $\boldsymbol{a_0}, \boldsymbol{a_1} \in A$, as above (having the same $y$ values but different $x$ values) such that $f(\boldsymbol{a_0}) \neq f(\boldsymbol{a_1})$.  We suppose $A$ is connected.  Since $\frac{\partial f}{\partial x} = 0$ everywhere in $A$, it seems like any curve in $f(A)$ that connects those points has to lie in a plane parallel to the $xy$ plane, else $f$ would change with changing $x$.  But if that were so, how could we have $f(\boldsymbol{a_0}) \neq f(\boldsymbol{a_1})$?
Clearly my intuition is failing me here.  Could somebody set me straight?
This is my first post on Math Exchange, please let me know if I'm doing something wrong.  Thanks!

REPLY [3 votes]: How about something like this.  Let the domain be a U-shaped region in $ \mathbb{R}^2 $,  with the straight legs of the $ U $ aligned with the y axis. Then lift up one leg of the U while keeping the round part at the bottom flat. This is the graph of such a function $ f(x,y) $. I hope this is intelligible..