vferraz
vferraz

Reputation: 469

Seaborn dashed line not dashed in the legend

I have the following chart:

sns.set_context("paper", font_scale = 1)

ax = sns.lineplot(x="generation", y="fitness", hue="Quadrant", data=dfnash)
ax.lines[4].set_linestyle(":")
ax.set_xlabel("Generation")
ax.set_ylabel("Fitness Scores (Aggregated Expected Utility)")
#ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
plt.tight_layout()
plt.savefig('nash7.png', dpi = 600, transparent=True)

enter image description here

I wanted one of the lines to be dashed, which is the "Entire Space" series, however the legend still shows a regular line. Is it normal behavior? Do I need to manually change something in the legend to follow the style I have in the chart?

Upvotes: 4

Views: 5632

Answers (1)

vferraz
vferraz

Reputation: 469

It turns out that it was quite easy to fix. You can get the legend lines individually, in the same way you get the chart lines.

leg = ax.legend()
leg_lines = leg.get_lines()
leg_lines[5].set_linestyle(":")

enter image description here

Upvotes: 5

Related Questions