Is there any difference between these two phrases? Is there any context in which we only can use one rather than the other?
My understanding is that in contrast is used to, well, contrast two ideas, or compare their differences. This does not imply that either idea is wrong, just that the two are contrasted.
"Kimchi is a Korean dish that is popular among millions. In contrast, many complain that it tastes like rotten cabbage".
The viewpoints are contradictory, but neither is necessarily correct.
On the contrary, however, is used when the writer or speaker wishes to emphasize a negative claim - that is, he brings a viewpoint that is explicitly not accepted, and the phrase is used to bring the alternate option:
"Kimchi's flavor is not rotten and naueseous, as some claim. On the contrary, it is a delightfully playful dish".
This is the BEST answer I have ever found (http://public.wsu.edu/~brians/errors/contrary.html):
The phrases “on the contrary” and “to the contrary” are used to reply to an opposing point. Your friend tells you she is moving to New York and you express surprise because you thought she hated big cities. She replies, “On the contrary, I’ve always wanted to live in an urban area.”
When a distinction is being made that does not involve opposition of this sort, “in contrast” is appropriate. “In New York, you don’t need a car. In Los Angeles, in contrast, you can’t really get along without one, though you won’t need a snow shovel.”
Here’s a simple test: if you could possibly substitute “that’s wrong” the phrase you want is “on the contrary” or “to the contrary.” If not, then use “in contrast.”
In contrast is used typically in the same way as on the other hand, when a writer is presenting two different views or making two different assessments, as in this example:
The music of Wagner and Mahler calls for large orchestras. In contrast, the music of a composer like Mozart can be performed with a relatively small number of musicians.
On the contrary would be inappropriate there. It is typically used to rebut an argument with some force, as in this example:
Some people think that capital punishment is a deterrent. On the contrary, it is no such thing, as the experience of many countries has shown.
In contrast would be just as inappropriate there as on the contrary would be in the previous example.
In contrast notes that the second statement stands in opposition to or complement of the first, but that both are true:
Red wine is normally served at room temperature and may benefit from being allowed to warm if stored somewhere cool. In contrast white and rosé wine is normally served chilled.
On the contrary is used when denying something in the first statement.
This rule is not absolute; on the contrary, the lighter Beaujolais wines are generally served chilled.
While on the contrary is used when the second statement asserts and the first denies, we use in contrast with two things that exclude each other, if we are reporting on them as opinions held by others:
Some hold the traditional matchings of food and wine to be important. Others, in contrast, argue that these are a means rather than an end and would say that if you really want to match a heavy beef stew with a light Sauvignon Blanc then go ahead and do so.
Because we aren't standing firmly behind either statement, but reporting on both. Our claim is that it is true that both opinions are held.
used to intensify a denial of what has just been implied or stated by suggesting that the opposite is the case [Example – there was no malice in her; on the contrary, she was very kind.]
the state of being strikingly different from something else in juxtaposition or close association [Example – the day began cold and blustery, in contrast to almost two weeks of uninterrupted sunshine.]
Clearly, there is a difference between the two phrases and I don't think they are interchangeable.