Maud van Lier
Maud van Lier

Reputation: 13

creating a two-headed arrow in a 3D plot

I am trying to create a very simple figure where one of the arrows should be double headed and the others are not. I want to work in matplotlib. In my code I can use the 'pivot' to change the direction of the arrow, but there does not seem to be an option for having a two-directed arrow. I have seen that this is possible with 2D plots, but for me it is important that it is in a 3D plot. Anyone an idea? Would be very much appreciated. This is my code:

import matplotlib.pyplot as plt
import numpy as np

# Define vectors
vectors = np.array([[0, 0, 18], [18, 0, 0], [0, 18, 0]])

# Origin point
origin = np.array([0, 0, 0])

# Plot setup`
fig = plt.figure()`
ax = fig.add_subplot(111, projection='3d')

# Define colors for each vector
colors = ['r', 'b', 'g']

# Plot vectors
for vector, color in zip(vectors, colors):
    ax.quiver(origin[0], origin[1], origin[2], vector[0], vector[1], vector[2],
              length=np.linalg.norm(vector), arrow_length_ratio=0.1, normalize=True,
              color=color, pivot='tail')

# Set plot limits
ax.set_xlim([-20, 20])
ax.set_ylim([-20, 20])
ax.set_zlim([-20, 20])

# Remove axis numbers and ticks
ax.set_axis_off()

# Set labels
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# Adjust the view angle so that arrowheads face towards the user
ax.view_init(elev=29, azim=45)

plt.show()

Upvotes: 0

Views: 63

Answers (0)

Related Questions