- numpy - matplotlib Physim

Plot Vector Scaling

In this section you will practice and apply what you have learned using the vector simulations, plotting vector scaling and understanding its properties.

Below is a graph of two vectors scaled by each other, one is the original vector, and another is the resultant scaled vector. Ask yourself these questions: What direction are the vectors pointing? How can I calculate the magnitude of these vectors? What are each these vector's components?


If you would like to see the full code for plotting the resultant scaled vector, click the Display Code button below:


# import required libraries import matplotlib.pyplot as plt def plot_vector_scaling(vector, scale): fig, ax = plt.subplots() ax.set_xlim(-10, 10) ax.set_ylim(-10, 10) # Plot the vectors ax.annotate("", xy=[vector[0], vector[1]], xytext=[0, 0], arrowprops=dict(arrowstyle="-|>,head_width=0.4,head_length=0.8", shrinkA=0, shrinkB=0, color='black', fill=True)) ax.annotate("", xy=[vector[0] * scale, vector[1] * scale], xytext=[vector[0], vector[1]], arrowprops=dict(arrowstyle="-|>,head_width=0.4,head_length=0.8", shrinkA=0, shrinkB=0, color='black', fill=True)) ax.annotate("", xy=[vector[0] * scale, vector[1] * scale], xytext=[0, 0], arrowprops=dict(arrowstyle="-|>,head_width=0.4,head_length=0.8", shrinkA=0, shrinkB=0, color='red', fill=True)) ax.set_xlabel('x-axis') ax.set_ylabel('y-axis') ax.set_title('Vector Scaling Plot') ax.grid(True) return plt vector = [2, 3] scale = 2 plot_vector_scaling(vector, scale)

Here is a code editor so that you can input a vector with the scale you would like to scale it with.


This is how the vector and scale inputs inputs should look like:

vector = [2, 3]

scale factor = 2

plot_vector_scaling is what creates a plot of the vector inputted and its resultant scaled vector.


vector = [2, 3] scale = 2 plot_vector_scaling(vector, scale)


Go Back to Vector Exercises Page