Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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),
                arrowprops=dict(arrowstyle='->'))

# 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
plt.show()

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.