0

I would like to draw plots which preserve symbolic meaning for certain numeric values.

In a isympy shell I can write:

T = Symbol('T')

plot(exp(x/T).subs(T, 5))

Which gives the following plot

enter image description here

I don't care much about the numeric tick labels in the plot. What I am interested in is where the x axis equals T=5 the y axis should equal e=2.718. In other words I want to discard all tick labels on both axis and only have one tick label on the x axis for T and one label on the y axis for e.

Is something like this possible?

Kevin
  • 3,096
  • 2
  • 8
  • 37

1 Answers1

1

According to Sympy and plotting, you can customize a sympy plot via accessing ._backend.ax. In my current version I needed ._backend.ax[0].

Here is how your plot could be adapted:

from sympy import Symbol, plot, exp

t_val = 5
T = Symbol('T')
plot1 = plot(exp(x / T).subs(T, t_val))
fig = plot1._backend.fig
ax = plot1._backend.ax[0]
ax.set_xticks([t_val])
ax.set_xticklabels([str(T)])
e_val = exp(1).evalf()
ax.set_yticks([e_val])
ax.set_yticklabels(["e"]) # or ax.set_yticklabels([f"{e_val:.3f}"]) ?
ax.plot([t_val, t_val, 0], [0, e_val, e_val], color='dodgerblue', ls='--')
fig.canvas.draw()

customizing sympy plot

JohanC
  • 71,591
  • 8
  • 33
  • 66