In [2]:
import math
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

drawing vectors


In [132]:
ax = plt.subplot(121)
ax.set_aspect(1.0)
ax.tick_params('both', length=10, width=1, direction='inout')

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

ax.spines['bottom'].set_position(('data', 0))
ax.spines['left'].set_position(('data', 0))

ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

ax.xaxis.set_ticklabels([-1, '', '', '', 3])
ax.yaxis.set_ticklabels(['', '', 2, '', ''])

ax.xaxis.set_ticks([-1, 0, 1, 2, 3])
ax.yaxis.set_ticks([0, 1, 2, 3])

ax.set_xlim(-2, 4)
ax.set_ylim(-1, 4)

plt.arrow(0, 0, 3, 2, head_length=0.25, head_width=0.15, ec='k', fc='k', length_includes_head=True, overhang=0.25)
plt.arrow(0, 0, -1, 2, head_length=0.25, head_width=0.15, ec='k', fc='k', length_includes_head=True, overhang=0.25)
plt.arrow(0, 0, 2, 4, head_length=0.30, head_width=0.15, ec='b', fc='b', length_includes_head=True, overhang=0.25)

plt.plot([-1, 2], [2, 4], 'k--')
plt.plot([2, 3], [4, 2], 'k--')

plt.annotate("$v$", (3.125, 2))
plt.annotate("$w$", (-1, 2), (-1.25, 2))
plt.annotate("$v + w$", (2, 4), (1.25, 2))

ax = plt.subplot(122)
ax.set_aspect(1.0)
ax.tick_params('both', length=10, width=1, direction='inout')

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

ax.spines['bottom'].set_position(('data', 0))
ax.spines['left'].set_position(('data', 0))

ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

ax.xaxis.set_ticklabels(['', '', 1, '', 3])
ax.yaxis.set_ticklabels([-2, '', '', 2])

ax.xaxis.set_ticks([-1, 0, 1, 2, 3])
ax.yaxis.set_ticks([-2, -1, 1, 2])

ax.set_xlim(-2, 4)
ax.set_ylim(-2, 3)

plt.arrow(0, 0, 3, 2, head_length=0.25, head_width=0.15, ec='k', fc='k', length_includes_head=True, overhang=0.25)
plt.arrow(0, 0, -1, 2, head_length=0.25, head_width=0.15, ec='k', fc='k', length_includes_head=True, overhang=0.25)
plt.arrow(0, 0, 1, -2, head_length=0.25, head_width=0.15, ec='k', fc='k', length_includes_head=True, overhang=0.25)
plt.arrow(0, 0, 4, 0, width=0.025, head_length=0.30, head_width=0.15, ec='b', fc='b', length_includes_head=True, overhang=0.25)

plt.plot([3, 4], [2, 0], 'k--')
plt.plot([1, 4], [-2, 0], 'k--')

plt.annotate("$v$", (3.125, 2))
plt.annotate("$w$", (-1, 2), (-1.25, 2))
plt.annotate("$-w$", (0.5, -2))
plt.annotate("$v - w$", (1.5, 0.25))

plt.gcf().set_figwidth(10)



In [ ]: