简体   繁体   中英

Show only exact values of data point on axes with matplotlib figure

I want to show only exact values (x, y) on axes or coordinates of data point by matplotlib. My work below that

def plot_sample_individual(id = None):
  if id is None:
    id = random.randint(0, len(ca_the))
  fig, ax = plt.subplots(1, 1, figsize=(5, 5))
  ax.plot(week[:7], ca_the[id, :],'--ro')
  ax.set_title('ID cá thể '+ str(ID[id, 0]))
  ax.set_ylabel('Sản lượng trứng trung bình tuần')
  ax.set_xlabel('Tuần')

and result of code is:

在此处输入图像描述

How to show only 3 values on axes y and 5 values in axes x?

Use the x and y data to set the Axes ticks :

from matplotlib import pyplot as plt
x = [24,25,26,27,28]
y = [7,4,5,4,4]
fig,ax = plt.subplots()
ax.plot(x,y)
ax.set_xticks(x)
ax.set_yticks(y)
plt.show()
plt.close()

Ticks and tick labels

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM