0

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

1
  • You're plotting x^5 for x in [0,1000], so it will show that entire range. Would it not be easier to define the range before plotting d? That way you can select the percentiles of the range to be plotted. Commented Apr 8, 2020 at 8:17

2 Answers 2

1

You can set the x range of your plot with:

plt.xlim(90, 100)

If this is what you want.

see xlim docu

Sign up to request clarification or add additional context in comments.

Comments

0

Just remove from my scripts

# plt.plot(d)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.