0

I wrote the following program that plots the shape as shown after the code:

length = 100
a = 50
b = 0
n = 2
alpha = np.radians(25.)
d = 18

x_nose = np.linspace(0,a,50)

r_nose = (0.5*d*(1. - ((x_nose-a)/a)**2.)**(1./n))

x_mid = np.linspace(a,(a+b),2)

r_mid = (((d/2) * np.ones(2)))

x_tail = np.linspace((a+b),length,50)

l_tail = (length - a - b)

r_tail = (0.5*d - ((3*d)/(2*l_tail**2) - np.tan(alpha)/l_tail)*(x_tail-a-b)**2 + (d/l_tail**3 - np.tan(alpha)/l_tail**2)*(x_tail-a-b)**3)

line1 = plt.plot(x_nose,r_nose,'k',x_mid,r_mid,'k',x_tail,r_tail,'k')
line2 = plt.plot(x_nose,-r_nose,'k',x_mid,-r_mid,'k',x_tail,-r_tail,'k')
plt.axis('equal')
plt.setp([line1,line2], linewidth=2)  
plt.show()

enter image description here

The formulas used to calculate the shape are however defined for length = 100. How can I scale the entire figure for a variable length?

2 Answers 2

1

You can apply a scaling factor, or even a linear transform, to each of the vectors that you're plotting

ax = 0.1 ; bx = -5.0 ; fx = lambda x: ax*x+bx
plt.plot(fx(x_head), r_head, fx(x_mid), r_mid, fx(x_tail), r_tail)
...

In the example above, I've just applied the scaling so that the x-axis limits are [-5, 5] and I didn't change the scaling on r, but you can apply the same scaling, or a different one, to the r vectors as you please.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm sorry but your answer does not really help me. I understand that I can apply a scaling factor to the points I am plotting but I do not understand your code.
0

You can use plt.xlim in the following way:

plt.xlim(-a*length, b*length)

where a and b are some coefficients of your choice (i.e. a=0, b=1)

1 Comment

I only want to scale some of the features in the plot. I fear that your method will cause all entities in the plot to be scaled?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.