Issue
When I plot a graph in Spyder using Matplotlib, the color red will be sometimes be dulled. For example,
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10,100)
y = 2*x
plt.plot(x,y, color = 'r', linewidth = 10)
plt.show()
will produce the image
instead of
If I restart Spyder after seeing the dulled red color, then it produces the good plot with the normal red color. I've only noticed this when plotting with the color red. The versions I'm using are Python 3.7.0, Spyder 3.3.4, IPython 7.2.0, and Matplotlib 3.0.2. I'm also using a Mac Mojave, if that's relevant.
Solution
Someplace before executing your code you will have a line saying something like
import seaborn as sns
sns.set(style="white")
or similar.
Complete code:
import seaborn as sns
sns.set(style="white")
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10,100)
y = 2*x
plt.plot(x,y, color = 'r', linewidth = 10)
plt.show()
The explanation is that seaborn.set
updates the colors if its color_codes
argument is set to True (which is the default).
color_codes
: bool IfTrue
andpalette
is a seaborn palette, remap the shorthand color codes (e.g. "b", "g", "r", etc.) to the colors from this palette.
There is also an example in the seaborn documentation.
So you can use
import seaborn as sns
sns.set(style="white", color_codes=False)
to get
or just not use .set
at all.
Answered By - ImportanceOfBeingErnest
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.