Matplotlib - 如何定义具有不同间隔的 x 轴,如下图所示?我想打开某些间隔

Matplotlib - How I can define the x-axis with different intervals like the next picture? I would like to open certain intervals

我想创建一个类似的图表,在这种情况下,中国和美国有巨大的 PIB,我看不到小国家的详细信息

为此,您可以使用 ax.set_xscale:

import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter

plt.scatter(your_data)
ax = plt.gca() #get current axis object
ax.set_xscale('log') #you can use 'symlog' if your data is close to 0
ax.set_yscale('log')
#if you don't want to show the ticks in scientific notation
for axis in [ax.xaxis, ax.yaxis]:
    formatter = ScalarFormatter()
    formatter.set_scientific(False)
    axis.set_major_formatter(formatter)