Matplotlib-如何像下一张图片一样定义具有不同间隔的x轴?我想打开某些时间间隔

问题描述 投票:0回答:1

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9FUXlWOC5wbmcifQ==” alt =“在此处输入图像描述”>

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

python matplotlib axis
1个回答
0
投票

为此,您可以使用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)
© www.soinside.com 2019 - 2024. All rights reserved.