Using Matplotlib to make a scatter plot (not Seaborn, Pandas, or other high-level interface), how can I use a dictionary to specify marker types?
This example works with a color dictionary:
x = [4, 8, 1, 0, 2]
y = [0.1, 1, 0.4, 0.8, 0.9]
name = ["A", "A", "B", "A", "B"]
df = pd.DataFrame(data=zip(x, y, name), columns=["x", "y", "name"])
colors = {"A": "red", "B": "blue"}
fig, ax = plt.subplots(1, 1)
ax.scatter(
x=df["x"],
y=df["y"],
facecolors="none",
edgecolors=df["name"].map(colors),
)
But the following throws an error TypeError: 'Series' objects are mutable, thus they cannot be hashed
:
markers = {"A": "v", "B": "D"}
fig, ax = plt.subplots(1, 1)
ax.scatter(
x=df["x"],
y=df["y"],
facecolors="none",
edgecolors=df["name"].map(colors),
marker=df['name'].map(markers),
)