-2

I currently have this function on matploblib:

x = np.arange(0,31)
y = x/(30-x)
plt.plot(x,y)
plt.ylabel('some numbers')
axes = plt.gca()
axes.set_ylim([0,3])
axes.set_xlim([0,25])
plt.show()

picture

However, I want to show only the numbers 3, 2 and 1/3 on the y axis and, corresponding to those numbers, 3T/4, 2T/3, T/4. Ideally, there would be a dashed line to indicate those points. (1/3, T/4), (2T/3, 2) and (3T/4, 3)

That is, I want to represent the equation X/(T-X), where T is a constant. Is that possible?

Peplm
  • 43
  • 1
  • 8
  • I haven't done the search myself, but we need to acknowledge if someone has honestly searched for the question already and doesn't know the term "xtick", we can't bomb-vote out people's question because us with greater knowledge can see what could be an answer. – AER Mar 29 '18 at 01:25

2 Answers2

0

Add axes.set_yticks([1/3, 2, 3]) to add the ticks only on the numbers 3, 2 and 1/3.

czr
  • 658
  • 3
  • 13
  • Thank you. What about the x axis? Is there a way I can place the strings "T/4", "TL/3" and "3T/4" in the corresponding x points? – Peplm Mar 29 '18 at 01:10
  • `axes.set_xticks([three points])` and `axes.set_xlabel(["T/4", "TL/3", "3T/4 ])`, three points corresponds to a list with the ticks location. – czr Mar 29 '18 at 01:12
0

Lemme make sure that I at least understand the first part of what you want. You want the x-axis to be labeled as "1/3", "2", "3", right?

This should do that part:

T = 30

# avoid divide by zero warning
x = np.arange(0.0001,31)
y = x/(T-x)
plt.plot(x,y)
plt.ylabel('some numbers')
ax = plt.gca()
ax.set_ylim([0,3])
ax.set_xlim([0,5])

ax.xaxis.set_ticks([1/3, 2, 3])
ax.xaxis.set_ticklabels(['1/3', '2', '3'])

enter image description here

tel
  • 13,005
  • 2
  • 44
  • 62