Self-insertion
Self-insertion is a literary device in which a fictional character, who represents the real author of a work of fiction, appears as an idealized character within that fiction, either overtly or in disguise.
In art, the equivalent is the inserted self-portrait, where the artist includes a self-portrait in a painting of a narrative subject. This has been a common artistic device since at least the European Renaissance.