Reputation: 17144
I have to create a plot that has axes suppressed and tangents drawn at regular intervals as shown in figure presented below.
Using R-programming, I know how to suppress tick marks and create the plot.
But I don't know how to suppress the whole axes.
Here, I need to omit the whole a-axis as well other axes such as top and right axes.
My initial try is this:
tau <- seq(-5,5,0.01)
a <- 0.4 # a is a constant parameter
sigma <- a*tau # tau is a variable, sigma = a*tau
x <- 1/a*cosh(sigma)
y <- 1/a*sinh(sigma)
# plot
plot(x,y,type="l",xaxt="n",yaxt="n")
abline(h=0,lty=1)
The plot also requires dots and tangents at points where a*tau = -1,-0.5, 0, 0.5 and 1
.
The links I followed are following:
Drawing a Tangent to the Plot and Finding the X-Intercept using R
Lines between certain points in a plot, based on the data? (with R)
The required plot looks like below:
Any suggestion both in python or R are truly appreciated!!
Upvotes: 3
Views: 362
Reputation: 879103
Using Python,
import numpy as np
import matplotlib.pyplot as plt
tau = np.arange(-5, 5, 0.01)
a = 0.4
sigma = a*tau
x = 1/a*np.cosh(sigma)
y = 1/a*np.sinh(sigma)
fig, ax = plt.subplots()
ax.plot(x, y, c='black')
# approximate the curve by a cubic
dxds = np.poly1d(np.polyfit(sigma, x, 3)).deriv()
dyds = np.poly1d(np.polyfit(sigma, y, 3)).deriv()
xs, ys, dxs, dys = [], [], [], []
for s in np.linspace(-1, 1, 5):
# evaluate the derivative at s
dx = np.polyval(dxds, s)
dy = np.polyval(dyds, s)
# record the x, y location and dx, dy tangent vector associated with s
xi = 1/a*np.cosh(s)
yi = 1/a*np.sinh(s)
xs.append(xi)
ys.append(yi)
dxs.append(dx)
dys.append(dy)
if s == 0:
ax.text(xi-0.75, yi+1.5, '$u$', transform=ax.transData)
ax.annotate('$a^{-1}$',
xy=(xi, yi), xycoords='data',
xytext=(25, -5), textcoords='offset points',
verticalalignment='top', horizontalalignment='left',
arrowprops=dict(arrowstyle='-', shrinkB=7))
ax.quiver(xs, ys, dxs, dys, scale=1.8, color='black', scale_units='xy', angles='xy',
width=0.01)
ax.plot(xs, ys, 'ko')
# http://stackoverflow.com/a/13430772/190597 (lucasg)
ax.set_xlim(-0.1, x.max())
left, right = ax.get_xlim()
low, high = ax.get_ylim()
ax.arrow(0, 0, right, 0, length_includes_head=True, head_width=0.15 )
ax.arrow(0, low, 0, high-low, length_includes_head=True, head_width=0.15 )
ax.text(0.03, 1, '$t$', transform=ax.transAxes)
ax.text(1, 0.47, '$x$', transform=ax.transAxes)
plt.axis('off')
ax.set_aspect('equal')
plt.show()
yields
Upvotes: 6