Bob
Bob

Reputation: 150

Plot in specific percentile range using python

I'm trying to plot the percentile.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab

d = np.array([pow(i,5) for i in range(1,1000)])

# Percentile values
p = np.array([10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0])

perc = mlab.prctile(d, p=p)

plt.plot(d)
# Place red dots on the percentiles
plt.plot((len(d)-1) * p/100., perc, 'ro')

# Set tick locations and labels
plt.xticks((len(d)-1) * p/100., map(str, p))

plt.show()

This is almost what I want enter image description here

But actually I prefer only shows the graph from 90 to 100 So I modified the p in my code

    p = np.array([99.0, 99.1, 99.2, 99.3, 99.4, 99.5, 99.6, 99.7, 99.8, 99.9, 100.0])

And now all the x index squeeze to the right side. And the plot still shows all data.

How can I fix this problem? enter image description here

Upvotes: 0

Views: 953

Answers (2)

Häcker
Häcker

Reputation: 11

You can set the x range of your plot with:

plt.xlim(90, 100)

If this is what you want.

see xlim docu

Upvotes: 1

Bob
Bob

Reputation: 150

Just remove from my scripts

# plt.plot(d)

Upvotes: 0

Related Questions