2

Can any one help me with this, i am new to graph a plot.

basically i have list of DocId's which are of some numbers and not necessarily in the order and this needs to come in X-Axies and timelst should come in Y-Axies.

below code actually plotting it, but DocId's not taken as respective DocID, its considered as range. so this needs to know and other thing is document list is huge may be i have 3000 - 5000 DocId's, can this graph goes for long for each DocID ?

import matplotlib.pyplot as plt
Doclst=   [32409057,32409058,32409059,32409060,32409061,32409062,32409063,32409065,32409066,32409067]
timelst=[120,1,4,35,675,1240,500,889,99,10]

plt.plot(Doclst, timelst, marker='o', linestyle='--', color='r', label='time')
plt.xlabel('Document ID'+"'"+'s')
plt.ylabel('Time in Seconds')
plt.title('Performance')
plt.legend()
plt.savefig('graph.png')

Please help me as early as possible.

1 Answer 1

1

Update: I added two lines, one to access the axis properties, and the other one to force all the labels to show. To avoid the labels to overlap, I add also the argument rotate in plt.ticks to rotate the label by 30°.

If I get right what you want, you should simply use plt.xticks to customize tick labels. You can do something like that

import matplotlib as mpl
import matplotlib.pyplot as plt
Doclst=   [32409057,32409058,32409059,32409060,32409061,32409062,32409063,32409065,32409066,32409067]
timelst=[120,1,4,35,675,1240,500,889,99,10]
fig, ax = plt.subplots()
plt.plot(Doclst, timelst, marker='o', linestyle='--', color='r', label='time')
plt.xlabel('Document ID'+"'"+'s')
plt.ylabel('Time in Seconds')
plt.title('Performance')
plt.legend()
plt.axis([Doclst[0], Doclst[-1], min(timelst)-1, max(timelst)+1])
ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(len(Doclst)+1))
locs,label = plt.xticks()
plt.xticks(locs, map(lambda x: "%d" %x, locs), rotation=30)
plt.show()

which will give you something like that output

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

3 Comments

Thanks MBR, this works perfectly. if i want this list to continue for some 2000 DocId's this x-axies will not run for 2000 and its ending with 8 DocIDs.
This is just Excellent work MBR, appreciate your turn arround time and great piece of information. thank you once again. this works just as i wanted.
You're welcome! By the way, welcome to StackOverflow! Since you are new, you might want to check this link.

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.