On modern fighter aircraft, why do most carry a rotary cannon when they tend to have little use against aircraft?
I think this question is highly opinion-based and should be closed. 

But here are my $0.02

Historically there were attempts to remove cannons but turns out too early: Missiles are not that good. The benefit of fallback weapon indeed outweight the weight. 


  MIG21 VS RF-4C
  
  One instance of combat during Project Dark Gene was an engagement on
  November 28, 1973 between an RF-4C aircraft piloted by IIAF Major
  Shokouhnia and backseater USAF Colonel John Saunders and a Soviet
  MiG-21 flown by Captain Gennadii N. Eliseev. The Soviet pilot fired
  two Vympel K-13 missiles at the Iranian aircraft, failing to destroy
  it. He was ordered from ground control to press his attack at any
  cost, and with his cannon jammed after the first shot,[8] he continued
  by ramming into the Iranian aircraft and losing his life in the
  process. He struck the RF-4C's tail assembly with his wing and then
  flew into high ground. It was the first deliberate jet-to-jet ramming
  by a Soviet aircraft during an interception, a practice common in the
  propeller age of World War II. Eliseev was posthumously awarded as a
  Hero of the Soviet Union.[3][9] The crew of the RF-4C aircraft were
  captured by Soviet ground forces and released after 16 days.2[10]


US military reached the same conclusion around the same time as well, to add cannons to F-4 Phantom II.

Maybe now is the time to rethink this question again after 40+ years advancement of AA missiles. But if you ask the pilot, for the same weight, do they want fuel, gun+ammo, or nothing? A significant portion, if not the majority, would pick the gun I guess. 

A lot of fighter pilots, or even astronauts, carry pistols. How useful is that?