Musical notes and colors of a rainbow I have wondered that in an octave in piano there are seven primary notes, and also we observe mostly seven primary colors of a rainbow. I know we perceive logarithmically, that means we only care about relative differences.
Is there any relation between $7$ musical notes (in an octave) and $7$ colors of a rainbow?
EDIT: I agree that the primary term for the $7$ notes in an octave is more or less the matter of taste. However, if we take the western musical taste as a guide, we can justify ourselves to use $12$ notes in an octave and place piano keys in the present way. Take a look at here.
 A: Answer to this question varies significantly based on point of view.
Physics & Physiology: No, there is no connection. The mechanisms are quite different (EM vs. acoustic spectrum, eyes vs. ears etc.) and number 7 is arbitrary.
Musicology & Aesthetics: Number 7 isn't that important, because in an octave there is actually 12 notes if we adopt western model and it is not the only option, vision does not have an octave-principle etc. On the other hand, there are numerous theories (but in context of this site let's label them "analogies") about visible color and tone (e.g. from Newton himself). This notion (part of a bigger phaenomenon called synesthesia) is psychological and experience-based. It lies on no physical principle - well, other than: "Waves! It all fits together, ya know?!"
A: On the most basic level, the answer is a flat no. The seven primary notes in an octave is specific to the western musical tradition. It's not entirely arbitrary as you say, but there are many other choices that could have been made, and there are other cultures who use fewer notes (e.g. pentatonic scales in blues music) or more (e.g. Indian classical music). The seven colours in the rainbow are also somewhat arbitrary. (Are indigo and violet really different colours? Why don't we count aquamarine, right between green and blue?)
Having said that, it does happen to be the case that the range of frequencies we can see is just a little short of an octave, ranging from about 440-770 THz. This is really more or less a coincidence, but because of it, I can point out a relationship between light and colours, just for fun.
The A above middle C is defined, for modern instruments, as 440Hz. The A an octave above is 880Hz, and in general if we go $n$ octaves up we get a frequency of $440\times 2^n$. If we go forty octaves up from A we get a note of 483 THz. This can't be played as a sound wave (air can't vibrate at frequencies that are too high) but as an electromagnetic wave it's a slightly reddish orange.
If we go down a note to G we get $392\times 2^{40}$ Hz $= 431$ THz, which is just into the infra-red. (It might be possible to see it as a very deep red colour, but I'm not sure.) However, moving up from there we get the following colours:


*

*G - 431 THz - infra-red

*A - 483 THz - orange

*B - 543 THz - yellow-green

*C - 576 THz - green

*D - 646 THz - blue

*E - 724 THz - indigo

*F - 768 THz - violet (barely visible)

*G - 862 THz - ultra-violet


(I leave the sharps and flats as an exercise to the reader.) So you can't see G (or F#), but the other notes do actually have colours.
However, as I said this is just a bit of fun and does not in any way have any practical implications, since sounds at those frequencies can't be transmitted through air.
A: The physiology viewpoint: totally different mechanisms.
The cochlea performs a mechanical Fourier transform. To some extent, we hear wavelengths. We can see a detailed explanation in The Human Ear -- Hearing, Sound Intensity and Loudness Levels.
But we don't see wavelengths. The different (usually three) types of cone cells are more or less sensitive to different (objective) wavelengths. Each (subjective) color is the product of this three signals.

A: What we perceive as colors are only a tiny fraction of the electromagnetic spectrum. An octave of piano notes represents a set of frequencies in the acoustic "spectrum" (light waves and sound waves are fundamentally different, by the way). The number 7 is arbitrary, we can name many more colors and we could define many more notes (on the piano we actually have 12 in an octave).
One more difference is that the rainbow contains the whole visible spectrum from red (large wavelength) to violet (short wavelength). Above and below that we are not able to perceive. One octave on the piano, on the other hand, is just one fraction. There are many octaves we are able to hear. The pattern repeats many times. Regarding 7/12 notes: music and physics yield a number of notes. But the number of colors in the rainbow is completely arbitrary. Where do you define boundaries between colors (e.g, yellow-green, bright-lime, citron)? It is continuous.
So from my perspective it is even more difficult to find relations than to find differences between "notes" and "colors".
A: As requested in comments:
There is a connection in the sense that Isaac Newton regarded both musical harmony and optical physics as branches of mathematics (Kepler did the same with harmony and astronomy, and this kind of thing was not original to them), and deliberately chose 7 rainbow colours to match the common Western scale, despite his poor eyesight initially only spotting 5 colours; he later added orange and indigo
Wikipedia's article on the rainbow says

Newton chose to divide the visible spectrum into seven colours out of a belief derived from the beliefs of the ancient Greek sophists, who thought there was a connection between the colours, the musical notes, the known objects in the Solar System, and the days of the week.

and includes a reference to a 2004 article by Niels Hutchison, MUSIC FOR MEASURE, On the 300th Anniversary of Newton's "Opticks"
A: Around 1665, when Isaac Newton first passed white light through a prism and watched it fan out into a rainbow, he identified seven constituent colors—red, orange, yellow, green, blue, indigo, and violet—not necessarily because that’s how many hues he saw, but because he thought that the colors of the rainbow were analogous to the notes of the musical scale.
Naming seven colors to correspond to seven notes is “a kind of very strange and interesting thing for him to have done,” says Peter Pesic, physicist, pianist, and author of the 2014 book Music and the Making of Modern Science. “It has no justification in experiment exactly; it just represents something that he’s imposing upon the color spectrum by analogy with music.”
Of his rainbow experiment Newton wrote that he had projected white light through a prism onto a wall and had a friend mark the boundaries between the colors, which Newton then named. In his diagrams, which showed how colors corresponded to notes, Newton introduced two colors—orange and indigo—corresponding to half steps in the octatonic scale. Whether Newton’s friend delineated indigo and orange on the wall or whether Newton added those colors to his diagrams in order to better fit his analogy is unclear, Pesic says. In any case, Newton’s inclusion of those two colors had lasting consequences, Pesic wrote in his book: “For those who came after, Newton’s musical analogy is the source of the widely held opinion that orange and indigo are actually intrinsic in the spectrum, despite the great difficulty (if not impossibility) of distinguishing indigo from blue, or orange from yellow, in spectra.”
Newton persisted with his color theory despite later data he had collected suggesting it was incorrect. When studying what are now called Newton’s rings—as seen, for example, in the rainbow of color in oily puddles—he noted that, according to the relationship between radii of colored rings, the range from red to violet was equivalent not to an octave but to something more like a major sixth. According to Pesic, rather than changing his theory to match the data, Newton came up with an erroneous explanation of how a major sixth was equivalent to an octave.
But as both musicians and physicists know, the two are not equivalent. In physics terminology, an octave is the frequency range from x to 2x, and that premise holds true for musical octaves. If light behaved like music, then photon frequencies of the spectrum would also range from x to 2x, and their wavelengths, inversely proportional to their frequencies, would too. Instead, the wavelengths of visible light range from 400 to 700 nanometers, which, if translated to sound waves, would be approximately equivalent to a major sixth, Pesic says.
Although Newton’s color-music analogy falls apart, his prism experiments showed that white light is actually a mix of different-colored lights, and this work was “a crucial step toward understanding the nature of light more deeply,” Pesic says. And even if you can’t make out indigo in the rainbow, you probably know ROY-G-BIV, which Pesic calls “a conventional expression of (and homage to) Newton’s choice [to name seven colors in analogy to music]—even though almost everyone has forgotten or did not know the odd story of its origin.”

