The first L.G.B.T.Q. outposts were often in marginal or neglected urban areas that allowed people who were considered outcasts to find homes and start businesses with relatively little opposition or capital. (Even today, gay men and lesbians earn less than heterosexuals, according to national surveys.) As gayborhoods, these communities improved and flourished, eventually becoming affluent and desirable places to live.

The Castro, in San Francisco, for example, had been somewhat abandoned by a working class exodus to the suburbs, creating an opening in the 1970s for gay and lesbian residents. Today the area is one of the most expensive residential districts in the nation. The average single-family home there sells for more than $2 million, according to a 2016 report compiled by the Paragon Real Estate Group, which studies the neighborhood. Market-rate two-bedroom apartments rent for about $4,400 a month, according to Rent Jungle, a company that tracks rents.

“Cities are changing in a very profound and new way,” Mr. Jones said, “with the rich claiming the inner cities.”

In Seattle, nearly every city neighborhood had an increased concentration of gay and lesbian residents from 2000 to 2012, except for the Capitol Hill gayborhood, which saw a 23 percent decrease.

Mr. Criscitello said gay residents there were priced out and outnumbered as thousands of new housing units were built in response to the booming local tech economy. New residents tend to be “heavily straight and heavily male,” Mr. Criscitello said, and able to pay higher rents.