3

how can I show the label of the value of each point I'm plotting on the y axis?

I am currently plotting like this:

d=[2,5,10,20,30,40,50,70,100,200]   
t0=[0.04,0.08,0.15,0.4,0.6,0.8,1.0,1.4,2.1,5.5]
fig, ax = plt.subplots()
plt.plot(d,t0,marker='o')
xmajorLocator = MultipleLocator(10)
xmajorFormatter = FormatStrFormatter('%d')
xminorLocator = MultipleLocator(1)
ymajorLocator = MultipleLocator(0.5)
ymajorFormatter = FormatStrFormatter('%.2f')
yminorLocator = MultipleLocator(0.05)
ax.xaxis.set_major_locator(xmajorLocator)
ax.xaxis.set_major_formatter(xmajorFormatter)
ax.xaxis.set_minor_locator(xminorLocator)
ax.yaxis.set_major_locator(ymajorLocator)
ax.yaxis.set_major_formatter(ymajorFormatter)
ax.yaxis.set_minor_locator(yminorLocator)
xlim([0,250])
show()

I just want the values of the t0 list to be marked and appear on the y axis, while keeping the current marks and ticks format.

user4288514
  • 75
  • 1
  • 5

1 Answers1

5
import matplotlib.pyplot as plt
d=[2,5,10,20,30,40,50,70,100,200]
t0=[0.04,0.08,0.15,0.4,0.6,0.8,1.0,1.4,2.1,5.5]
fig, ax = plt.subplots()
plt.plot(d,t0,marker='o')
ax.set_xticks(d)
ax.set_yticks(t0)
plt.show()

enter image description here

cphlewis
  • 15,759
  • 4
  • 46
  • 55
  • Thanks man, and how do I format the mark's text? It overlaps since some values are too close. – user4288514 Apr 21 '15 at 00:37
  • What kind of formatting would you do? You could leave some of those values out of the ticklist (edit a slice out of d). – cphlewis Apr 21 '15 at 00:39
  • (a) that's a different question and (b) it's answered [here](http://stackoverflow.com/questions/6390393/matplotlib-make-tick-labels-font-size-smaller) – cphlewis Apr 21 '15 at 00:50