The Friends episode that featured Phoebe thinking her mother has come back to her in cat form was penned by a writer whose own mother had recently died. Other staff writers have said that the script — which earned primarily negative responses from the audience — would not normally have been greenlit, but under the circumstances nobody felt comfortable saying 'no.'
An example of the trope in fiction: One episode of Boy Meets World involves Eric dating the aspiring singer/songwriter Corinna (played by real-life singer Leisha Hailey), whose songs are saccharine and completely unappealing. When he dumps her, she immediately starts writing dark and angry songs clearly directed at him; these sell, and she becomes a huge success. After a while she meets with Eric, ostensibly to apologize, but he quickly realizes she's just run out of material. Refusing to give her any, he acts nice to Corinna and manages to revert her to mindless schlock mode. Part of their conversation consists of singing some of "Tomorrow" from Annie. (The episode even openly references Alanis Morissette, who had a similar transformation—see "Music", below.) At the end of the episode, Eric gives an evil snicker once her cheerful albums bomb again.
A similar example to the above occurs on Seinfeld, when Jerry tells a would-be stand-up comic who he finds annoying that she's not funny. So, of course, when she premieres an act that centers entirely around insulting Jerry (and this isn't even telling jokes about him - this is pretty much just actually nakedly insulting him), she becomes a hit.note The comic is played by Kathy Griffin, whose real-life comedy act consists of making fun of celebrities.
In-Universe example: Brian Topp in Spaced, whose default setting for all of his art is angsty, bizarre pieces directly based on his misery, fear, anger and self-loathing - except when he's happy, in which case he starts producing happy pictures of flowers and his girlfriend.
Worse yet, misery, fear, anger and self-loathing are his muses; Brian can only produce art at all when miserable, and eventually his inspiration dries up if he doesn't have something to breakdown over.
Tim gets in on the act as well; flipping through his sketchbook one night, Daisy is alarmed and disturbed by the sheer volume of graphic, angry and hurt revenge pictures of Tim's ex-girlfriend, who betrayed him by cheating on him with her boss and kicked him out of their flat; then, she comes across a warm, happy sketch of Tim, herself and her dog Colin drawn after they moved in together.
Portrayed in Mad About You: Jamie discovers that her ex-boyfriend has created his own comic whose primary villain, Queen Talon, looks exactly like Jamie. Reading through his work, she discovers several events that are exaggerated sci-fi versions of incidents from their relationship.
Deliberately played for laughs in Garth Marenghi's Darkplace, in which the Show Within a Show presents more of an insight into the eponymous author's mindset than he perhaps realizes or wishes, especially his feelings about women. Of particular note is an episode which is essentially an extended racist tirade at the Scottish; played for laughs in that the English Marenghi loudly insists that it's not racist despite the overwhelmingly obvious evidence that it is, including another character who freely admits that it is, but didn't bother him because he too is prejudiced against the Scottish.
In Babylon 5, Stephen Franklin quits his job and goes wandering around the seedier parts of the station. Eventually he's stabbed and nearly dies. Some time after the episode aired, J. Michael Straczynski was asked if he'd ever done anything similar. He described how he used to wander around the seedier parts of San Diego, late at night, until he was mugged and beaten nearly to death. Until then he hadn't made the connection.
Which might also explain why San Diego is a nuclear wasteland in the Babylon 5 'verse.
"So, to all my friends in San Diego, this is my shout-out to you." (Director's Commentary.)
Straczynski got a bad flu late in the process of writing the first season, and when he came out of it the script for the episode "The Quality of Mercy" was on his desk. To date he has no memory of actually writing it, but it's surprisingly lucid given the circumstances.
A more positive result of Creator Breakdown was Michael Piller's script for "The Best of Both Worlds, Parts 1 & 2;" Riker's career crisis, loss of faith in himself and antagonistic relationship with his possible replacement, Shelby, was inspired by Piller's angst over his own career path as a writer. Today, the two-part season finale is remembered as some of the best television Trek has ever produced.
Matt Albie and Harriet Hayes' relationship in the short lived Studio 60 on the Sunset Strip was largely thought to have been inspired by Aaron Sorkin's tumultuous real life relationship with Kristen Chenoweth. Also, in the same show Danny Tripp is unable to continue to direct movies for the time being after failing an insurance physical drug test — Sorkin having had similar drug-related issues in the past.
For that matter, Studio 60 also features an in-universe example in the first episode: after being forced to cut a sketch making fun of the religious right (and, we learn later, having been increasingly unhappy with the direction of the show for years), show creator Wes Mendel walks out on camera during the live broadcast and delivers a 57 second diatribe on how his show used to be cutting edge satire, but that a combination of ratings obsession by the network and low-brow reality TV is intellectually lobotomizing the public.
Dennis Potter's Karaoke and Cold Lazarus were written in tandem (for different networks!) in the full and present awareness of his own impending death from pancreatic cancer. The former of these is a reasonably traditional drama (with standard Potteresque touches). The latter, however, picks up the same central (Potter-analogue) character, four hundred years later after he's had his head cryogenically frozen. Things get significantly weirder from there. It's arguable, of course, whether or not this actually represents a great shift from the pre-illness output!
Parodied in Castle; over the later episodes of season two, Detective Tom Demming appears as a rival over Beckett's attentions and affections for the eponymous novelist. He's quite successful, displacing Castle in several ways. Not long after, a character called 'Detective Schlemming' makes his way into later drafts of Castle's most recent novel.
Alexis: This robbery detective character... he seems to come out of nowhere. Castle: [Troubled for reasons obviously beyond writing] I can't argue with that... Alexis: He seems like kind of a doofus. Castle: [Eagerly] Yeah? You think?
Not to mention the show's whole premise - that he's basing a character in his novels on Detective Beckett...
A bit of a meta / Fridge Brilliance example: in the first season, a Running Gag is that Castle killed off his previous character, Derrick Storm, because he was bored with him. Looking over the (fictional) bibliography provided at the character's website, the blurbs for several of the works featuring this character seem to suggest a number of increasingly unsubtle (and no doubt ignored) hints from Castle that he's a bit bored with this guy and would like to stop writing him now, please.
Another in-universe example occurs in the Criminal Minds episode "True Night", where the killer, a comic book artist, creates an extremely violent comic starring what appears to be a Nineties Anti-Hero, because of the same issues (watching his pregnant girlfriend die at the hands of street thugs) that are making him kill. In fact, his art is based on his murders.
In How I Met Your Mother, main character Ted's former love interest's husband writes a romantic comedy directly based upon the events leading up to him winning the woman away from Ted, but in a drastically distorted POV that shows him as a hero and Ted as an obnoxious heel (played by real-life obnoxious heel Chris Kattan). The movie then goes on to be a huge hit.
Parodied on Community when Vaughn breaks up with Britta, he cowrites a song called "Getting Rid of Britta" that consists of the refrain "She's a GDB" sung multiple times.
In Documentary Filmaking Redux Dean Pelton completely breaks down trying to film a commercial for Greendale, and warps the entire school around, cancelling all classes. Abed decided to document the whole thing because he predicted this would happen. The whole episode is a parody of Hearts of Darkness, which gets lampshaded repeatedly.
Abed: The Dean is going insane and taking all of you with him.
Some fans have also argued that the quality slump in season 3 of the show could be attributed to real-life personal problems that show creator Dan Harmon was going through at the time.
An in-universe example in Degrassi. Eli writes a play after he breaks up with Clare, even naming the character that breaks the main character's heart Clara and naming the guy who stole her from him Jack (after Clare's new boyfriend Jake).
Speaking of J. Michael Straczynski, this was what likely led to him to breaking certain taboos when he wrote certain episodes of Captain Power and the Soldiers of the Future the way he did, including at least two instances of swearing, and a(n intended-to-be season) finale in which an important good guy character was killed off onscreen. In an interview he mentions that he had known someone who had taken their own life, despite his best efforts to save them, which likely resulted in him invoking this trope. Had the series continued, it would have featured more Darker and Edgier plotlines.
The increasing powerlessness and incompetence of the First Doctor over his tenure was partially a response to William Hartnell's failing health. His inability to remember lines and hatred of everyone else in the crew put him constantly in a bad mood and gives his character a genuine frailty, which the writers generally wrote towards (bad memory can be disguised with fewer lines to say, and bad mood can be hidden with going Darker and Edgier).
The unusual characterisation of the Fourth Doctor in Season 18 is because Tom Baker was seriously burned out with the role after doing it both onscreen and offscreen for seven years and because the line between his own personality and the Doctor's had been getting increasingly blurry - not least he was physically unwell. Thus, he played the role as primarily moody and vulnerable with the comedy bits being deliberately strained, a harsh contrast with his usual manic and exuberant personality. Once his departure was known by the writers it was turned into an Arc where every story was linked by themes of mortality and decay, foreshadowing his upcoming regeneration.