When I run the below code, I get a figure with gradient color (from black to orange). Please look at the attached figure. Whereas I want to get a figure only with single color, orange (not figure with a gradient color). How can I do that?
My code:
#!/usr/bin/python3
import numpy as np
import pylab as plot
import matplotlib.pyplot as plt
import numpy, scipy, pylab, random
from matplotlib.ticker import MultipleLocator
import matplotlib as mpl
from matplotlib.ticker import MaxNLocator
import seaborn as sns
import pandas as pd
fig, ax = plt.subplots(figsize=(4, 2))
df = pd.read_csv('input.txt', sep="\s\s+", engine='python')
sns.kdeplot(data=df, label = "s1", color = "orange", cmap=None)
plt.xlabel('x', fontsize=7)
plt.ylabel('y', fontsize=7)
for axis in ['top','bottom','left','right']:
ax.spines[axis].set_linewidth(0.5)
plt.savefig("plot.png", dpi=300, bbox_inches='tight')
input.txt:
0.43082 0.45386
0.35440 0.91632
0.16962 0.85031
0.07069 0.54742
0.31648 1.06689
0.57874 1.17532
0.18982 1.01678
0.31012 0.54656
0.31133 0.81658
0.53612 0.50940
0.36633 0.83130
0.37021 0.74655
0.28335 1.30949
0.11517 0.63141
0.24908 1.04403
-0.28633 0.46673
-0.13251 0.33448
-0.00568 0.53939
-0.03536 0.76191
0.24695 0.92592
Using Seaborn v0.11.2.
Solution:
The expected output is obtained if you specify
x
andy
arguments ofseaborn.kdeplot
as the column names of the DataFrame (after appropriately reading the data as suggested in Timeless's answer, i.e., by specifyingheader=None
inpd.read_csv
):df
:Expected figure output:
sns.kdeplot
plots distribution of each column in the data whendata
is passed to it without specifyingx
andy
:The code in the question throws an error:
If you now don't pass
cmap
tosns.kdeplot
and use:it returns (notice the legend labels of the line plots):