<｜begin▁of▁sentence｜>### Instruction:
Given a NetworkX graph with edge set [(1, 2), (2, 3), (3, 4), (4, 1)], can you handle 'pick' events in a matplotlib plot to identify and print the node that was clicked by the user?
### Response:
import matplotlib.pyplot as plt
import networkx as nx

# Example of interactive plot with NetworkX and matplotlib

class GraphArtist:
    def __init__(self, graph):
        self.graph = graph
        self.fig, self.ax = plt.subplots()
        self.pos = nx.spring_layout(graph)

    def draw(self):
        nx.draw(self.graph, self.pos, ax=self.ax, with_labels=True)
        self.cid = self.fig.canvas.mpl_connect('pick_event', self.pick)

    def pick(self, event):
        artist = event.artist
        index = event.ind
        node = list(self.graph.nodes())[index[0]]
        print(f'Node {node} was picked')

# Create a NetworkX graph and initialize the GraphArtistG = nx.Graph()
G.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 1)])
artist = GraphArtist(G)
artist.draw()
# Enable pick event and show the plotplt.gcf().canvas.mpl_connect('pick_event', artist.pick)
nx.draw_networkx_nodes(G, artist.pos, ax=artist.ax, picker=True)  # Nodes are now pickableplt.show()
<|EOT|>
