Reputation: 443
I am trying to make a graph from my csv data file. My code is as follow:
for name in per_data.dtype.names[2:]:
plt.plot(per_data['RELEASE'],per_data[name],label=name)
plt.legend(loc='upper left',prop = {'size':7},bbox_to_anchor=(1,1))
plt.tight_layout(pad=5)
plt.xlabel ('Release')
plt.ylabel ('Time/Sec')
plt.title ('Ingest Performance Test')
plt.grid()
plt.show()
my csv data is:
DATE RELEASE 10GB 100GB 200GB 400GB 600GB 800GB 1000GB
5/5/16 2.67 0.36 4.18 8.54 18 27 38 46
5/5/16 2.68 0.5 4.24 9.24 18 27 37 46
5/6/16 2.69 0.32 4.3 9.18 19 29 37 46
5/6/16 2.7 0.35 4.3 9.3 19 28 37 46
5/6/16 2.71 0.3 4.18 8.18 16 24 33 41
as you can see, I am using the 2nd column -- RELEASE as my x-axis label. The issue is: the actual release numbers are: 2.67, 2.68, 2.69 ,2.70, 2.71 However, in the graph the program added extra point (2.65, 2.75, 2.85, 2.95, and 2.705). How do I set it so the label of x-axis will reflect my release number?
Upvotes: 2
Views: 33274
Reputation:
You need to use plt.xticks()
as shown here. It controls what ticks and labels to use for your x-axis.
In your example, you will have to add another line as shown below:
for name in per_data.dtype.names[2:]:
plt.plot(per_data['RELEASE'],per_data[name],label=name)
plt.legend(loc='upper left',prop = {'size':7},bbox_to_anchor=(1,1))
plt.tight_layout(pad=5)
plt.xlabel ('Release')
plt.xticks (per_data['RELEASE'])
plt.ylabel ('Time/Sec')
plt.title ('Ingest Performance Test')
plt.grid()
plt.show()
Upvotes: 8