A precocious, gifted youth who dropped out of education and took a job as a gravedigger so he could sit around in graveyards reading poetry: a notorious drug taker and carouser, harassed by the law, misunderstood by society: a foppish androgynous dandy, dangerous and unpredictable, with beautiful paramours: a rebellious artist-hero, a melancholic genius. A portrait of a classic 19th century romantic? Not at all. These are details from the biography of tabloid favourite, supermodel-consort and part time singer-songwriter Pete Doherty. They amply illustrate that the romantic myth of the artist continues to hold a strong grip over our national psyche. Despite the old-fashioned pretentiousness of the rebel pose there is something tenacious about this particular composite of outsider, visionary and martyr.

A new show at the National Gallery, Rebels and Martyrs: The Image of The Artist in the Nineteenth Century, sets out to tell the story of this construct - which the art critic Michael Wilson describes in his essay which accompanies the catalogue as the "visionary outsider, battling against a hostile, philistine society" - through two centuries of painting. As this flagship show suggests it is an image that emerged at the end of the 18th century and was consolidated by the romantic movement. It is also a thoroughly gendered image.

The artist has nearly always stood as the social, cultural and sexual counterpart of respectable masculinity: free-wheeling, independent, expressive, in excess in every way of the dominant norms of male behaviour, as special type of being whose creativity was driven by, or even a manifestation of, his sexual energies. This is the core of the myth around which additional meanings and associations are woven, but what all of these ideas have in common is that the male artist is different from most other men; they are mad, bad and dangerous to know. They are sublime dreamers and creators whose visions and desires are beyond the comprehension of ordinary mortals.

Visual representations, across a range of media including paintings, photographs and films, have played a central role in the dissemination of this myth. Popular culture in particular has borrowed from the romantic myth to construct an idea of the artist in the popular imagination. From Anthony Quinn's portrayal of Gauguin in Vincente Minelli's 1955 biopic of Van Gogh, Lust for Life, to Alec Guinness's loveable but disreputable Gulley Jimson in the 1958 film of Joyce Carey's novel The Horse's Mouth, to the hapless wannabe bohemian played by Tony Hancock in the Ray Galton's 1960 satirical comedy The Rebel, the romantic artist - though not necessarily taken completely seriously - is a recognisable staple. The sensation-seeking antics of the young British artists of the 1990s gave a knowing postmodern twist to the hardy myth of the bohemian artist, living outside society's stifling norms (the curators reinforce this by quoting Emin in the publicity materials).

Since the 18th century, images have allowed us to visualise what it is to be an artist and the psychological and physical qualities that differentiate the artist from other types of men and, occasionally, women.

James Barry's Self Portrait of around 1780 is an excellent early example of the artist as loner and misunderstood genius. At the end of the 18th century Barry was an isolated advocate of a grand style of historical painting that was finding little support with the artistic establishment. At the time of the portrait he was in the middle of one of his most ambitious and successful commissions, but one that paid practically nothing beyond the costs of materials and models. Barry was the original starving artist in the garret - satirised nearly two hundred years later by Tony Hancock - and was to face further rejection and alienation in the years leading up to 1800. He depicts himself as deep in thought, set apart against a dark background, his expression care-worn and his gaze focussed on a space beyond the viewer in the realm of the imagination.

Fashion and artistic identity have always been closely interwoven. The myth of the artist is about a 'look', a style, a form of self-fashioning that is a statement of social and sexual nonconformity. By the middle of the 19th century, the myth had undergone a number of transmutations, including an adoption of the persona of the dandy, that nonchalant inhabitant of the streets of the modern metropolis who was so powerfully evoked in the writings of Charles Baudelaire. The dandy artist was a subtle negotiation of the artist as outsider and as bourgeois. He adopted some of the most stylish mannerisms of fashionable masculinity in this period, but was distant and removed, a dispassionate observer of the manners and modes of contemporary bourgeois society.

Fantin-Latour's portrait of Edouard Manet, 1867, shows the artist through the filter of this new artistic identity. Gone are the unkempt and dreamy qualities of the romantic bohemian and instead there are gloves, top hat and cane; the tailoring of the boulevardier, the flâneur who wanders the public spaces of the modern city in search of new subjects and styles. This move was self-conscious, a deliberate way of positioning oneself within the competitive and tough conditions of the Parisian art world, of turning the image of the artist into a kind of commodity.
Many of the most compelling and enduring images of the modern artist have, at best, been difficult for women to adopt and, at worst, entirely closed to them. And yet women have been essential to the construction of images of the male artist. They represent the base matter, the material that is transformed by the genius into the stuff of great art; they are his muse, his inspiration and object of desire. It is not surprising, therefore, that in this exhibition there are a number of images of the male artist with a female model in which the woman functions as a sign of the artist's creative power and sexual authority. Lovis Corinth's Self Portrait as a Model, 1903, draws on elements of the romantic image but adds a 20th-century spin. It shows the artist standing, facing out towards the viewer, dressed in a loose white shirt and holding paint brushes and palette in his right hand. His gaze is absorbed and stern and his body is strong and unyielding.

A few years earlier, Corinth had opened a school for women artists. Charlotte Berend, the model in the painting, had been one of his first pupils and had married him a few months before the picture was made. There is no sign of Berend's own artistic identity, however. She is simply body; unclothed, with her back to us and standing against the clothed body of the artist/lover/husband, with her hand placed on his heart. Her dark hair and white flesh are as important as signs of Corinth's artistic identity as the brushes and palette he holds in his hand.
Women artists could and did intervene in this imagery, but they had to navigate a range of powerful assumptions about the relationship between gender and creativity and between respectability and social exclusion. In Paula Modersohn-Becker's 1906 Self Portrait on her Sixth Wedding Anniversary, the artist adopts a modern style of painting and depicts herself stripped to the waist and cradling a pregnant belly. Modersohn-Becker was not pregnant at this time, however and in spite of the title, during the previous year she has left her husband and had rejected many of the institutional conventions of respectable femininity. She uses both her style and her self-image in order to play with the traditional meanings of female creativity and to present a surprisingly disobedient image of the modernist artist.

The French structuralist writer, Roland Barthes, defined mythology as a set of beliefs that are repeated with such frequency and effectiveness that they take on the status of a natural and inevitable truth.

So the disparity between the reality of what it is to be an artist at any historical moment and the myth of artistic creativity is not the point. What matters are the values and meanings that are disseminated through this ongoing mythology and what they can tell us about prevailing norms of social and cultural relations, about what it is that we want the artist to symbolise within the contemporary world.

Perhaps in place of the rebel our contemporary notion of the artist is more like Damien Hirst, a millionaire with a team of assistants and celebrity friends. But is there still a residual belief in the artist as the suffering genius? Do we still need the artist to represent something autonomous and wild that we feel has been forced out of mainstream society and most of our daily lives? As we get safer and more compliant is there something about the outsider, the self-destructive loner who refuses to conform, that we need now more than ever?