Python 具有matplotlib的x轴的不同比例

Python 具有matplotlib的x轴的不同比例,python,matplotlib,plot,graphics,cdf,Python,Matplotlib,Plot,Graphics,Cdf,我试图为不同的值列表(包含在不同的文件中)绘制CDF。 代码如下: import argparse, os, math import fileLibrary import numpy as np import matplotlib.pyplot as plt parser = argparse.ArgumentParser() parser.add_argument('-d', type=str, dest='intervalsDir', help='the directory which c

我试图为不同的值列表(包含在不同的文件中)绘制CDF。 代码如下:

import argparse, os, math
import fileLibrary
import numpy as np
import matplotlib.pyplot as plt

parser = argparse.ArgumentParser()
parser.add_argument('-d', type=str, dest='intervalsDir', help='the directory which contains all the intervals for the CDF')
arguments = parser.parse_args()
intervalsDir = arguments.intervalsDir

def cdf(dataList, groupName):
    dataLen = len(dataList)
    dataSet = sorted(set(dataList))
    bins = np.append(dataSet, dataSet[-1]+1)
    counts, binEdges = np.histogram(dataList, bins=bins, density=False)
    counts = counts.astype(float) / dataLen
    cdf = np.cumsum(counts)
    plt.plot(binEdges[0:-1], cdf, linestyle='--',  color='b')
    plt.ylim((0,1))
    plt.ylabel("CDF")
    plt.xlabel(groupName)
    plt.grid(True)
    plt.show()

for fileName in os.listdir(intervalsDir):
    parsedFileName = fileName.split(".")
    xLabel = parsedFileName[0]
    filePath = intervalsDir + "/" + fileName
    dataList = fileLibrary.createFileList(filePath)
    myDataList = []
    for d in dataList:
        x = int(d)
我得到以下结果(对于第一个文件,其他文件类似):

我从中获取CDF的值列表由0到1000之间的大多数值组成。然后我有很少的大数字,我只有2个接近最后一个25万的数字。每个列表包含60000多个值。 我希望我的x轴有不同的刻度,主要显示较小的值。 我是python和matplotlib新手,所以我不知道如何正确地做到这一点。
提前感谢您的帮助。

您能否将
plt.plot(binEdges[0:-1],cdf,linestyle='--',color='b')
替换为
plt.semilogx(binEdges[0:-1],cdf,linestyle='--',color='b')
并查看它是否对您有帮助?这基本上是在x轴上使用对数刻度。请试一试。或者,如果不想切换到对数比例,可以尝试不连续的x轴,其中显示的数据最多为1000,然后接近最后的x值。这是链接,您的第一个解决方案正是我想要的,非常感谢!:)我会检查第二个以及!很高兴你成功了!不客气