Search code examples
pythonmatplotlibplotaxis-labels

Python Matplotlib - Show Tick Marks associated to Plotted Points


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.


Solution

  • 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