<｜begin▁of▁sentence｜>### Instruction:
Given a NetworkX graph representing a social network (such as the Karate club graph), can you use the GraphArtist.get_datalim method to determine and set the axes limits for plotting the graph with Matplotlib, ensuring that all the nodes and edges fit into the canvas with a small padding?
### Response:
from matplotlib import pyplot as plt
from networkx.drawing.nx_agraph import GraphArtist
import networkx as nx

# Create a NetworkX graph
G = nx.karate_club_graph()

# Generate layout data for the graph
pos = nx.spring_layout(G)

# Initiate a Matplotlib figure
fig, ax = plt.subplots()

# Create a GraphArtist instance with the NetworkX graph and the layout
artist = GraphArtist(G, pos)

# Get data limits from the GraphArtist
datalim = artist.get_datalim(ax)

# Set limits on axes
ax.set_xlim(datalim[0], datalim[1])
ax.set_ylim(datalim[2], datalim[3])

# Draw the graph
artist.draw()

# Display the plot
plt.show()
<|EOT|>
