Ask Your Question

What's the method to include multiple arrows in matplotlib and mendeleev without having to write them individually?

asked 2023-05-26 13:31:15 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-05-26 13:34:01 +0000

ladyg gravatar image

One way to include multiple arrows in matplotlib and Mendeleev without having to write them individually is to use a loop to iterate through a list of arrow positions and add each arrow to the plot. Here's an example code snippet that demonstrates this:

import matplotlib.pyplot as plt
from mendeleev import element

# Define arrow positions
arrow_positions = [(1, 2), (2, 5), (4, 1)]

# Set up plot
fig, ax = plt.subplots()

# Loop through arrow positions and add arrows to plot
for x, y in arrow_positions:
    ax.annotate('', xy=(element('C').atomic_number, x), xytext=(element('O').atomic_number, y),

# Set axis labels and limits
ax.set_xlabel('Atomic number')
ax.set_ylabel('Some variable')
ax.set_xlim(0, 20)
ax.set_ylim(0, 10)

# Show plot

In this example, we define a list of arrow positions (arrow_positions) as tuples of (x, y) coordinates. We then loop through this list and add an arrow at each position using the ax.annotate() function, which takes the starting and ending coordinates of the arrow as xy and xytext arguments, respectively, and sets the arrow style using the arrowprops argument.

This approach allows us to easily add multiple arrows to a plot without having to write out each set of arrow coordinates individually.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2023-05-26 13:31:15 +0000

Seen: 1 times

Last updated: May 26