Issue
The last line does not change the size of markers(handles) in my graph. I have tried all mentioned options (as comment). In all the cases, the markerscale remains 1
What is my mistake? Thanks!
plt.figure(figsize=(100, 30))
sns.set(font_scale = 10)
color_map = {'Inhibitors':'green','Normal':'black', 'Inducers': 'red'}
g= sns.lineplot(x='Plate format' , y='Spots/Area_Normalized', data=df_Sample, hue='Compounds2_Normalized', palette=color_map, estimator=None, ci=None, sort=False, linewidth=15)
g.set(xlabel='wells of plate', ylabel=' EVs per cell area')
g.set(ylim=(0, 0.016), yticks=[0, 0.002, 0.004, 0.006, 0.008, 0.01, 0.012, 0.014,0.016])
plt.yticks(fontsize=100)
plt.xlabel('Small molecules', fontsize=100)
plt.ylabel('Number of EVs per cell area (µm²) ', fontsize=100)
plt.setp(g.get_legend().get_texts(), fontsize='100') # for legend text
plt.setp(g.get_legend().get_title(), fontsize='100') # for legend title
g.legend(markerscale = 10) # Or mpl.rc('legend', markerscale = 10) Or mpl.rcParams['legend.markerscale'] = 10
Solution
If you want to increase the thickness of handles in the legend you can use:
for legobj in legend.legendHandles:
legobj.set_linewidth(4)
Example:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({'x': [1, 2, 3],
'A': [3, 2, 5],
'B': [1, 4, 3]})
df = pd.melt(frame = df, id_vars = 'x', var_name = 'group', value_name = 'y')
g = sns.lineplot(data = df, x = 'x', y = 'y', hue = 'group')
legend = g.legend()
for legobj in legend.legendHandles:
legobj.set_linewidth(4)
plt.show()
markerscale
parameter increase the size of markers, so you actually need to have markers on your plot, but seaborn.lineplot
, with the parameters you used, draws a line without markers.
You can activate markers with style
and markers
parameters:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({'x': [1, 2, 3],
'A': [3, 2, 5],
'B': [1, 4, 3]})
df = pd.melt(frame = df, id_vars = 'x', var_name = 'group', value_name = 'y')
g = sns.lineplot(data = df, x = 'x', y = 'y', hue = 'group', style = 'group', markers = ['o', '^'], dashes = False)
g.legend(markerscale = 3)
plt.show()
Answered By - Zephyr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.