The Pyro is known for high standard damage at short ranges, and ambush capabilities (Soup's answer addresses your specific situation quite succinctly), but can do more than just spew fire in his/her general personal space, and can actually be pretty effective in long-range offense.
However, while the game therefore categorizes him/her as an offensive class — and most players do choose Pyro for the frontlines — he/she makes an equally useful defensive or utility class. (This isn't as much a secret to the Pyro class per se, as just a trait of his/hers that isn't known to many players as a consequence of obsessively one-sided marketing.) So whenever you're bored of popping up and lighting everything on fire, retreat and use some other tactics to continue keeping enemy forces at bay, and your team strong.
My loadout these days is Degreaser, Flare Gun and Homewrecker. My answer leans a bit toward defensive strategies and a bunch of other Pyro tactics, but I'm aware that you're more into offense, so there are some useful things to know about offense as well.
Hopefully these tips will help you maximize your time as Pyro and make your gameplay more interesting, because many people are still under the age-old impression that all the Pyro does is run around burning stuff. They may not get you a lot more kills, but hey, this isn't Solo Fortress, right?
Pyros are also renowned as the best class for spychecking. See (or set) someone glowing the opposite team color on fire? It's either an enemy or a cloaked/disguised Spy.
Unfortunately I'm not the perfect spychecker, but I think I'll pass. I just happen to play against good Spies who completely avoid the spots where I check, time their Dead Ringers very accurately, and are excellent quickstabbers.
I optimized my loadout for spychecking. The Degreaser speeds up weapon switching, the Flare Gun ignites and crits easily (good for their low health), and the Homewrecker removes sappers in a single hit with free points to boot.
While you're dedicating yourself to a particular area on the map, check every nook and cranny. Sweep fire and shoot flares just about anywhere that isn't a wall or object; you never know if a Spy could be there. And then check open areas, as some clever Spies may stand out in the open to avoid Pyros who only look at corners. Amid all this, though, remember that you're just one person, so it's OK if you're checking one area constantly when a Spy suddenly starts picking off teammates in another. Of course, you ought to move to that other area immediately if the Spy is there, but that's beside the point.
If you see someone suspicious approaching buildings or teammates, try to blow them back with airblast... unless you're standing or walking behind him of course. If he gets thrown back by it, then fire at will. Pun or not.
By the way... if you keep getting stabbed by a good Spy, my friend who mains as Spy tells me this: it's not that you're a bad Pyro, it's just that that's a good Spy. So don't sweat it, just do better next time, I guess. It happens to me a lot, so I know how frustrating that can get, and I'm only just starting to learn to take it in my stride.
Compression blast (aka airblast)
Compression blast is pretty much the only reason why I main as Pyro. It's the most versatile ability he/she has.
If you see teammates on fire, go to them and blow the fire out. Seriously. Not only does doing so grant you free points (1 per person you blow out), you save their lives too, especially Medics, who have slightly lower health than you. I've once earned 100 points in a single match from putting out fires alone because the other team kept sending W+M1s down unused tunnels to flank us. If your burning teammates are running away from you, probably to any available medkits, it helps to call out to them saying you're right behind them and to let you catch up. This is very helpful if you know they won't be able to reach a medkit before burning to death.
Additionally, with the Hatless Update, using the Backburner no longer means you should only be attacking. If you're recharging at your base or Engie nests, it's a good idea to keep some of that ammo for extinguishing your teammates and pushing ÜberCharges away.
Other defensive uses of compression blast include point denial on capturing and defending objectives, as well as pushing stickies and ÜberCharges away from your team. Just make sure to push them outward, not inward. If they're near a ledge, shove them off it to render them useless.
Offensive airblast (my favorite sport) against rockets and grenades, on the other hand, is mostly about timing. About direction too, but more about timing, particularly with grenades and Direct Hits, because you're still more often trying to protect your teammates from them than trying to give them a taste of their own medicine.
Once you become really good at timing, you can take on Huntsman Snipers, level 3 Sentry Guns, Soldiers with Direct Hits and Kritzed Medic-Soldier/Demo pairs on your own, and win. I do the latter two on a regular basis, and it's pretty satisfying (examples 1 and 2). Remember that when you deflect critical shots, the self-damage is reduced. One thing you should note, though, is that you should never go up against Kritzed Demos using stickies. They will kill you as you can't change the affected team by deflecting them, unlike other projectiles. Just run.
Compression blast is also useful versus level 3 Sentries situated far away or high up. If an Engineer is there, get its attention; once it fires rockets, deflect them such that they point above or beside it, causing the splash damage to kill the Engineer and allowing your teammates to finish it off — or you to do it, with more of its deflected rockets.
For a list of everything the compression blast can deflect, see this answer.
One last thing: while under the effects of a Medic's Kritzkrieg, your airblast turns almost all projectiles critical, including Sentry rockets and baseballs but with the exception of stickies. Just something interesting to note, but I recommend that you tell your Kritz Medics to go with Soldiers, Heavies or Demos instead.
Shotgun or Flare Gun?
I don't like my Shotgun because my aiming with it is pretty bad — in fact, I don't recall ever killing anyone with a single critical shot. That's how bad I am. Surprisingly, though, I'm pretty good with my flares; plus, since the Hatless Update, they serve me at least 75% of my critical kills.
If you're more into close combat and your aim is good, you'll definitely prefer the Shotgun. Its standard damage ranges can quickly kill many classes in a 6-shell clip, at a short enough range. It's also obviously better against enemy Pyros, but when I encounter them I'm usually shoving them aside with my airblast rather than embedding bullets in them.
Equip the Flare Gun for long-range combat. Flares may take excruciatingly long to reload, but the nice thing is that they take long enough for you to switch to the Degreaser to deflect oncoming projectiles, nifty for heckling Soldiers and Demos. Plus, besides random crits, they also guarantee 90 standard critical damage on burning enemies, which is just barely half of the Axtinguisher's 195. The Shotgun only has random crits.
The Flare Gun is very effective against Engineers repairing their buildings, slow Snipers and Snipers who can't twitch-shot, stationary Heavies and anyone you're busy holding in place with airblast.
Another benefit the Flare Gun has is with Spychecking (as above). The Shotgun is terrible against cloaked/disguised Spies from a medium distance, because it's difficult to track the damage. But the Flare Gun? One shot to reveal them, another to kill.
Whichever secondary weapon you choose, the Pyro's taunt kill is one of the quickest, but not with as great a range as the Heavy's.
Axtinguisher or Homewrecker?
The most commonly-used Pyro melée weapons are the Axtinguisher and the Homewrecker, so I'll cover those.
The Axtinguisher is a great offensive melée weapon. You probably already know the "puff-and-sting" technique; if not, it's simply a matter of puffing someone to a wall or corner with airblast, then stinging them with the Axtinguisher. In fact, that's pretty much what this weapon's meant for. When I play offensive, most of my kills are from airblasts, flares or my Axtinguisher.
The Homewrecker, though, is a lovely weapon of (potentially mass) building destruction. It can do away with Mini-Sentries in a single hit, and other buildings in two hits, unless Wrangled or repaired. With it, Engies won't be able to slow you down too much with Mini-Sentries. For regular Sentry Guns, make it a point to get the Engies first, then focus on melting or bashing their toys.
If you'd like to pick up defensive Pyro play someday, carry the Homewrecker with you, and spend a good amount of time near your Engineer nests. Even if there aren't any Engineers in your team, it can be useful to have it around in case someone decides to help the team out with teleporters or sentries.
When a Spy appears and starts sabotaging your Engineer nests, kill the Spy first, then unsap the buildings one by one (just like the versus-Engineer strategy). Or, if he starts swinging his knife or firing his revolver, you could unsap the Sentry first and let it kill him for you. If he's on the other side of a teleporter, you should alert your teammates. Be careful not to let him telefrag you if you're on the exit!
General tips for combat, etc.
While waiting in ambush behind walls and facing door openings, hold your secondary or melée weapon out so your flamethrower doesn't stick out and give your position away. With the Degreaser's faster weapon-switch bonus, the enemy has even less time to react to spotting you when they aren't expecting anyone there.
It's alright that the Degreaser suffers from a slight afterburn nerf. You shouldn't rely on afterburn to kill anyone but lite classes anyway, whichever primary weapon you use. Spew as much fire as you can, and puff and sting them before they can get a chance to escape. Even if they do slip away, either the Shotgun or Flare Gun will easily bring them down.
Get good with circle-strafing and you can easily take out slow-turning Heavies and Sentry Guns propped against one or no walls even without a Medic buff, much less an ÜberCharge, whether you use the Flamethrower or the Axtinguisher/Homewrecker respectively.
Despite what people say about W+M1, you can use it effectively with a surprise ÜberCharge. Even if you don't want to use W+M1, you can go W+M2 instead, sending the enemy team in all directions to disorient them real bad. As an added bonus, if you have helpful teammates at all, they can follow the Über and do the dirty work for the two of you. Just don't confuse your folks too. If you encounter any Soldiers, Demos or level 3 Sentries during your ÜberCharge, try deflecting their projectiles toward their teammates or buildings to deal some collateral damage.