31

I'd like to superimpose one plot over another (they are polygons, really in some lat/lon space, using geopandas, but the plot is simply derived from matplotlib)

I have:

figZ, axZ = plt.subplots(1, figsize=(11,8.5))
Sfig = X.plot(ax=axZ, color='white', edgecolor='black', lw=0.7)
Y.plot(ax=axZ, color='white', edgecolor='black', lw=0.7, alpha=0.3)

How do I set Sfig's color to "no-fill" instead of white? The way it is now it "blurs" my Sfig image (X.plot) by the alpha of the Y.plot one. How do I set "color" to actually transparent?

0

3 Answers 3

57

I don't expect upvotes, but this is what I found as solution. I'll vote up better ones if they exist:

Sfig = X.plot(ax=axZ, facecolor="none", 
              edgecolor='black', lw=0.7)
Sign up to request clarification or add additional context in comments.

3 Comments

"none" is exactly how you specify no color in matplotlib
I noticed that in windows, I can do facecolor='', but on Linux I have to enter as by the answer facecolor='none'
for latest matplotlib the argument name is markerfacecolor
1

I know this post doesn't mention seaborn, but I suspect a lot of people end up here asking this question for seaborn also (as I did).

The top answer almost works for seaborn boxplots, you just need to pass it as boxprops.

sns.boxplot(data=data, x=x, y=y, hue=hue, boxprops=dict(facecolor="none"))

NOTE: I emphasise that this solution only works for boxplots. There is a more general was of doing this with the new object API in seaborn.

2 Comments

This is not generally true for seaborn and depends on the type of plot you initiate. Depending on the underlying plot structure, you can often define edgecolor and facecolor but in some types, seaborn overrules the user setting.
Ah yes. I just went down a rabbit hole of following github issues around discussing general solutions. I will emphasise that my solution is only relevant to boxplots.
0

To disable facecolor just set with the value (0, 0, 0, 0), i.e.,

Sfig = set_facecolor((0,0,0,0))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.