The ancient Greeks found a very telling metaphor to describe the phenomenon of the relationship between artistic inspiration and sexuality: as I discuss in the second link above, it is the idea of the muses. The Greeks, in the person of Plato, invented the very idea of the Ideal, the Perfect, which could only be imperfectly embodied in concrete reality. Plato's metaphor of the Cave resonates with us still. These ideal perfections we only perceive imperfectly, like shadows on the wall of the cave. So the Greeks invented the Muses, nine daughters of Zeus and Mnemosyne ('memory'), that were the personification of knowledge and the arts. The very idea of 'personification' is deeply Platonic.
We can see how the muses function in the modern world in the career of Picasso. Here is a website that collects on one page all the women that were muses for Picasso between 1904 and 1973. For example, around the time of Guernica, Picasso was living with and inspired by Dora Mar, whom he described as his "private muse". Here is Dora and a painting of her by Picasso:
Picasso's muse/lovers were all young attractive women between the ages of 17 and 29. He fell in love with and had children with many of them. As Robert Graves notes,
A Muse-poet falls in love, absolutely, and his true love is for him the embodiment of the Muse... But the real, perpetually obsessed Muse-poet distinguishes between the Goddess as manifest in the supreme power, glory, wisdom, and love of woman, and the individual woman whom the Goddess may make her instrumentFrom one point of view, Picasso's dalliances with these many women (at least eight) might seem shallow, but understood from the perspective of inspiration, perhaps it makes more sense. I'm not sure I can really explain it, but I have certainly felt it, many times.
In order to create something, energy is required. You may be working, struggling with the materials for hours, days, weeks, months. Or years. You don't know exactly what you are doing or where you are going, but this energy animates you and perhaps in some way directs you. Because this energy is a particular kind of energy. It is the energy of life. Dynamic, burgeoning. You meet someone that seems to embody an ideal of beauty, of creation and you simply must respond to that. What you create is a homage, not just to an individual woman, but to all women. To life, because it is only young women who can create life, who hold the future of all humanity.
It is unfortunate that the depiction of sexuality in our contemporary world is so crude, so blatant and so ubiquitous. We do everything we possibly can to erase the magic and mystery of sexuality. I wonder if growing up with a never-ending succession of sexualized music videos short-circuits the possibility of muse-like inspiration...
Not all art and certainly not all music has this kind of inspiration. Not all artists are like Picasso. But perhaps there is a bit of muse-inspiration in all art. Other things that drive inspiration, at least for me, are things like need. I have written quite a bit of music simply because there was an ensemble that needed it. Here is a post about a piece I wrote for guitar orchestra because we needed some music. Other times it was Nature that was the inspiration. I wrote a piece called "Unbounded Vision in Blue and Purple" inspired by a seascape. Inspiration is like a grain of sand dropped into a supersaturated solution that causes crystallization. Or it is like a grain of sand inside the shell of an oyster that causes it to cover the irritant with layers of pearl.
But whatever the catalyst, the artist, in order to bring the work into being, needs a flow of energy. The energy of sexuality is often the most suitable. Some artists, like Picasso or Bach (who had thirteen children by two wives) are very prolific sexually as well as artistically. Other artists, like Beethoven, who never married or fathered children, seem to transmute all or most of their sexuality directly into the art.
Let's end with some music by Beethoven, the very passionate Piano Sonata No. 8, the "Pathétique":