How Do I Remove an Attribute from the Legend of a Scatter plot
I did a scatter plot
using seaborn
from three columns ['Category','Installs' and 'Gross Income']
and a hue map using the category column from my dataset. However in the legend, other than the category column which I want to appear, there is a big smug at the end showing one of the columns used in the scatter plot, Installs. I'll like to remove this element, but from searching through other questions hear and the documentation of seaborn
and matplotlib
I'm at a loss on how to proceed.
Here is a snippet of the code I'm working with:
fig, ax = pyplot.subplots(figsize=(12,6))
ax=sns.scatterplot( x="Installs", y="Gross Income", data=comp_income_inst, hue='Category',
palette=sns.color_palette("cubehelix",len(comp_income_inst)),
size='Installs', sizes=(100,5000), legend='brief', ax=ax)
ax.set(xscale="log", yscale="log")
ax.set(ylabel="Average Income")
ax.set_title("Distribution showing the Earnings of Apps in Various Categoriesn", fontsize=18)
plt.rcParams["axes.labelsize"] = 15
# Move the legend to an empty part of the plot
plt.legend(loc='upper left', bbox_to_anchor=(-0.2, -0.06),fancybox=True, shadow=True, ncol=5)
#plt.legend(loc='upper left')
plt.show()
python matplotlib seaborn scatter-plot
add a comment |
I did a scatter plot
using seaborn
from three columns ['Category','Installs' and 'Gross Income']
and a hue map using the category column from my dataset. However in the legend, other than the category column which I want to appear, there is a big smug at the end showing one of the columns used in the scatter plot, Installs. I'll like to remove this element, but from searching through other questions hear and the documentation of seaborn
and matplotlib
I'm at a loss on how to proceed.
Here is a snippet of the code I'm working with:
fig, ax = pyplot.subplots(figsize=(12,6))
ax=sns.scatterplot( x="Installs", y="Gross Income", data=comp_income_inst, hue='Category',
palette=sns.color_palette("cubehelix",len(comp_income_inst)),
size='Installs', sizes=(100,5000), legend='brief', ax=ax)
ax.set(xscale="log", yscale="log")
ax.set(ylabel="Average Income")
ax.set_title("Distribution showing the Earnings of Apps in Various Categoriesn", fontsize=18)
plt.rcParams["axes.labelsize"] = 15
# Move the legend to an empty part of the plot
plt.legend(loc='upper left', bbox_to_anchor=(-0.2, -0.06),fancybox=True, shadow=True, ncol=5)
#plt.legend(loc='upper left')
plt.show()
python matplotlib seaborn scatter-plot
Possible duplicate of Seaborn: title and subtitle placement
– Diziet Asahi
Nov 22 at 20:45
add a comment |
I did a scatter plot
using seaborn
from three columns ['Category','Installs' and 'Gross Income']
and a hue map using the category column from my dataset. However in the legend, other than the category column which I want to appear, there is a big smug at the end showing one of the columns used in the scatter plot, Installs. I'll like to remove this element, but from searching through other questions hear and the documentation of seaborn
and matplotlib
I'm at a loss on how to proceed.
Here is a snippet of the code I'm working with:
fig, ax = pyplot.subplots(figsize=(12,6))
ax=sns.scatterplot( x="Installs", y="Gross Income", data=comp_income_inst, hue='Category',
palette=sns.color_palette("cubehelix",len(comp_income_inst)),
size='Installs', sizes=(100,5000), legend='brief', ax=ax)
ax.set(xscale="log", yscale="log")
ax.set(ylabel="Average Income")
ax.set_title("Distribution showing the Earnings of Apps in Various Categoriesn", fontsize=18)
plt.rcParams["axes.labelsize"] = 15
# Move the legend to an empty part of the plot
plt.legend(loc='upper left', bbox_to_anchor=(-0.2, -0.06),fancybox=True, shadow=True, ncol=5)
#plt.legend(loc='upper left')
plt.show()
python matplotlib seaborn scatter-plot
I did a scatter plot
using seaborn
from three columns ['Category','Installs' and 'Gross Income']
and a hue map using the category column from my dataset. However in the legend, other than the category column which I want to appear, there is a big smug at the end showing one of the columns used in the scatter plot, Installs. I'll like to remove this element, but from searching through other questions hear and the documentation of seaborn
and matplotlib
I'm at a loss on how to proceed.
Here is a snippet of the code I'm working with:
fig, ax = pyplot.subplots(figsize=(12,6))
ax=sns.scatterplot( x="Installs", y="Gross Income", data=comp_income_inst, hue='Category',
palette=sns.color_palette("cubehelix",len(comp_income_inst)),
size='Installs', sizes=(100,5000), legend='brief', ax=ax)
ax.set(xscale="log", yscale="log")
ax.set(ylabel="Average Income")
ax.set_title("Distribution showing the Earnings of Apps in Various Categoriesn", fontsize=18)
plt.rcParams["axes.labelsize"] = 15
# Move the legend to an empty part of the plot
plt.legend(loc='upper left', bbox_to_anchor=(-0.2, -0.06),fancybox=True, shadow=True, ncol=5)
#plt.legend(loc='upper left')
plt.show()
python matplotlib seaborn scatter-plot
python matplotlib seaborn scatter-plot
edited Nov 23 at 3:52
Ali AzG
585515
585515
asked Nov 22 at 20:05
Daniel1234
255
255
Possible duplicate of Seaborn: title and subtitle placement
– Diziet Asahi
Nov 22 at 20:45
add a comment |
Possible duplicate of Seaborn: title and subtitle placement
– Diziet Asahi
Nov 22 at 20:45
Possible duplicate of Seaborn: title and subtitle placement
– Diziet Asahi
Nov 22 at 20:45
Possible duplicate of Seaborn: title and subtitle placement
– Diziet Asahi
Nov 22 at 20:45
add a comment |
1 Answer
1
active
oldest
votes
Actually, that is not a smudge but the size legend for your hue map. Because the bubble sizes (100, 5000)
are so large relative to data, they overlap in that space in legend, creating the "smudge" effect. The default legend combines both color and size legends together.
But rather than remove the size markers as you intend, readers may need to know the range Installs size for bubbles. Hence, consider separating one legend into two legends and use borderpad and prop size to fit the bubbles and labels.
Data (seeded, random data)
categs = ['GAME', 'EDUCATION', 'FAMILY', 'WEATHER', 'ENTERTAINMENT', 'PHOTOGRAPHY', 'LIFESTYLE',
'SPORTS', 'PRODUCTIVITY', 'COMMUNICATION', 'PERSONALIZATION', 'HEALTH_AND_FITNESS', 'FOOD_AND_DRINK', 'PARENTING',
'MAPS_AND_NAVIGATION', 'TOOLS', 'VIDEO_PLAYERS', 'BUSINESS', 'AUTO_AND_VEHICLES', 'TRAVEL_AND_LOCAL',
'FINANCE', 'MEDICAL', 'ART_AND_DESIGN', 'SHOPPING', 'NEWS_AND_MAGAZINES', 'SOCIAL', 'DATING', 'BOOKS_AND REFERENCES',
'LIBRARIES_AND_DEMO', 'EVENTS']
np.random.seed(11222018)
comp_income_inst = pd.DataFrame({'Category': categs,
'Installs': np.random.randint(100, 5000, 30),
'Gross Income': np.random.uniform(0, 30, 30) * 100000
}, columns=['Category', 'Installs', 'Gross Income'])
Graph
fig, ax = plt.subplots(figsize=(13,6))
ax = sns.scatterplot(x="Installs", y="Gross Income", data=comp_income_inst, hue='Category',
palette=sns.color_palette("cubehelix",len(comp_income_inst)),
size='Installs', sizes=(100, 5000), legend='brief', ax=ax)
ax.set(xscale="log", yscale="log")
ax.set(ylabel="Average Income")
ax.set_title("Distribution showing the Earnings of Apps in Various Categoriesn", fontsize=20)
plt.rcParams["axes.labelsize"] = 15
# EXTRACT CURRENT HANDLES AND LABELS
h,l = ax.get_legend_handles_labels()
# COLOR LEGEND (FIRST 30 ITEMS)
col_lgd = plt.legend(h[:30], l[:30], loc='upper left',
bbox_to_anchor=(-0.05, -0.50), fancybox=True, shadow=True, ncol=5)
# SIZE LEGEND (LAST 5 ITEMS)
size_lgd = plt.legend(h[-5:], l[-5:], loc='lower center', borderpad=1.6, prop={'size': 20},
bbox_to_anchor=(0.5,-0.45), fancybox=True, shadow=True, ncol=5)
# ADD FORMER (OVERWRITTEN BY LATTER)
plt.gca().add_artist(col_lgd)
plt.show()
Output
Even consider seaborn's theme with sns.set()
just before plotting:
Thanks a mill @Parfait!!! This looks way much better than what I intended to do. You are quite right that it is helpful to maintain the installs legend, it gives perspective to the graph. Thanks again. However when I ran your code it only showed the installs legend and left out the category legend. Also on my system it still shows triple dots unlike the more elegant single color dot in your output. what can I do about that as well?
– Daniel1234
Nov 23 at 9:33
Weirdly enough when I switched the order by declaringsize_lgd
first and thencol_lgd
theplt.gca().add_artist(size_lgd)
produced the legends. Though it would still be helpful to know how I can change my output from using 3 colored circles to one like yours. All the same thanks for the help. I really appreciate it.
– Daniel1234
Nov 23 at 9:53
Hmmm...I wonder if we are having version issues. I just upgraded both matplotlib and seaborn:pip install --upgrade modulename
and this solution is reproduced. Also, it could be a data issue. Can you reproduce the legend and color issue with my posted data example? If so, try posting a few sample rows of your actual data.
– Parfait
Nov 23 at 15:57
I think it had to do more with some default settings on my system. I was able to trace the settings that needed adjustment and I was able to reproduce the appearance of your output. Both in thesize_lgd
andcol_lgd
I addedmarkerscale=0.3, scatterpoints=1
and it changed the number of appearing scatterpoints from three to one. Thanks again you were really a big help.
– Daniel1234
Nov 24 at 22:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437462%2fhow-do-i-remove-an-attribute-from-the-legend-of-a-scatter-plot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Actually, that is not a smudge but the size legend for your hue map. Because the bubble sizes (100, 5000)
are so large relative to data, they overlap in that space in legend, creating the "smudge" effect. The default legend combines both color and size legends together.
But rather than remove the size markers as you intend, readers may need to know the range Installs size for bubbles. Hence, consider separating one legend into two legends and use borderpad and prop size to fit the bubbles and labels.
Data (seeded, random data)
categs = ['GAME', 'EDUCATION', 'FAMILY', 'WEATHER', 'ENTERTAINMENT', 'PHOTOGRAPHY', 'LIFESTYLE',
'SPORTS', 'PRODUCTIVITY', 'COMMUNICATION', 'PERSONALIZATION', 'HEALTH_AND_FITNESS', 'FOOD_AND_DRINK', 'PARENTING',
'MAPS_AND_NAVIGATION', 'TOOLS', 'VIDEO_PLAYERS', 'BUSINESS', 'AUTO_AND_VEHICLES', 'TRAVEL_AND_LOCAL',
'FINANCE', 'MEDICAL', 'ART_AND_DESIGN', 'SHOPPING', 'NEWS_AND_MAGAZINES', 'SOCIAL', 'DATING', 'BOOKS_AND REFERENCES',
'LIBRARIES_AND_DEMO', 'EVENTS']
np.random.seed(11222018)
comp_income_inst = pd.DataFrame({'Category': categs,
'Installs': np.random.randint(100, 5000, 30),
'Gross Income': np.random.uniform(0, 30, 30) * 100000
}, columns=['Category', 'Installs', 'Gross Income'])
Graph
fig, ax = plt.subplots(figsize=(13,6))
ax = sns.scatterplot(x="Installs", y="Gross Income", data=comp_income_inst, hue='Category',
palette=sns.color_palette("cubehelix",len(comp_income_inst)),
size='Installs', sizes=(100, 5000), legend='brief', ax=ax)
ax.set(xscale="log", yscale="log")
ax.set(ylabel="Average Income")
ax.set_title("Distribution showing the Earnings of Apps in Various Categoriesn", fontsize=20)
plt.rcParams["axes.labelsize"] = 15
# EXTRACT CURRENT HANDLES AND LABELS
h,l = ax.get_legend_handles_labels()
# COLOR LEGEND (FIRST 30 ITEMS)
col_lgd = plt.legend(h[:30], l[:30], loc='upper left',
bbox_to_anchor=(-0.05, -0.50), fancybox=True, shadow=True, ncol=5)
# SIZE LEGEND (LAST 5 ITEMS)
size_lgd = plt.legend(h[-5:], l[-5:], loc='lower center', borderpad=1.6, prop={'size': 20},
bbox_to_anchor=(0.5,-0.45), fancybox=True, shadow=True, ncol=5)
# ADD FORMER (OVERWRITTEN BY LATTER)
plt.gca().add_artist(col_lgd)
plt.show()
Output
Even consider seaborn's theme with sns.set()
just before plotting:
Thanks a mill @Parfait!!! This looks way much better than what I intended to do. You are quite right that it is helpful to maintain the installs legend, it gives perspective to the graph. Thanks again. However when I ran your code it only showed the installs legend and left out the category legend. Also on my system it still shows triple dots unlike the more elegant single color dot in your output. what can I do about that as well?
– Daniel1234
Nov 23 at 9:33
Weirdly enough when I switched the order by declaringsize_lgd
first and thencol_lgd
theplt.gca().add_artist(size_lgd)
produced the legends. Though it would still be helpful to know how I can change my output from using 3 colored circles to one like yours. All the same thanks for the help. I really appreciate it.
– Daniel1234
Nov 23 at 9:53
Hmmm...I wonder if we are having version issues. I just upgraded both matplotlib and seaborn:pip install --upgrade modulename
and this solution is reproduced. Also, it could be a data issue. Can you reproduce the legend and color issue with my posted data example? If so, try posting a few sample rows of your actual data.
– Parfait
Nov 23 at 15:57
I think it had to do more with some default settings on my system. I was able to trace the settings that needed adjustment and I was able to reproduce the appearance of your output. Both in thesize_lgd
andcol_lgd
I addedmarkerscale=0.3, scatterpoints=1
and it changed the number of appearing scatterpoints from three to one. Thanks again you were really a big help.
– Daniel1234
Nov 24 at 22:23
add a comment |
Actually, that is not a smudge but the size legend for your hue map. Because the bubble sizes (100, 5000)
are so large relative to data, they overlap in that space in legend, creating the "smudge" effect. The default legend combines both color and size legends together.
But rather than remove the size markers as you intend, readers may need to know the range Installs size for bubbles. Hence, consider separating one legend into two legends and use borderpad and prop size to fit the bubbles and labels.
Data (seeded, random data)
categs = ['GAME', 'EDUCATION', 'FAMILY', 'WEATHER', 'ENTERTAINMENT', 'PHOTOGRAPHY', 'LIFESTYLE',
'SPORTS', 'PRODUCTIVITY', 'COMMUNICATION', 'PERSONALIZATION', 'HEALTH_AND_FITNESS', 'FOOD_AND_DRINK', 'PARENTING',
'MAPS_AND_NAVIGATION', 'TOOLS', 'VIDEO_PLAYERS', 'BUSINESS', 'AUTO_AND_VEHICLES', 'TRAVEL_AND_LOCAL',
'FINANCE', 'MEDICAL', 'ART_AND_DESIGN', 'SHOPPING', 'NEWS_AND_MAGAZINES', 'SOCIAL', 'DATING', 'BOOKS_AND REFERENCES',
'LIBRARIES_AND_DEMO', 'EVENTS']
np.random.seed(11222018)
comp_income_inst = pd.DataFrame({'Category': categs,
'Installs': np.random.randint(100, 5000, 30),
'Gross Income': np.random.uniform(0, 30, 30) * 100000
}, columns=['Category', 'Installs', 'Gross Income'])
Graph
fig, ax = plt.subplots(figsize=(13,6))
ax = sns.scatterplot(x="Installs", y="Gross Income", data=comp_income_inst, hue='Category',
palette=sns.color_palette("cubehelix",len(comp_income_inst)),
size='Installs', sizes=(100, 5000), legend='brief', ax=ax)
ax.set(xscale="log", yscale="log")
ax.set(ylabel="Average Income")
ax.set_title("Distribution showing the Earnings of Apps in Various Categoriesn", fontsize=20)
plt.rcParams["axes.labelsize"] = 15
# EXTRACT CURRENT HANDLES AND LABELS
h,l = ax.get_legend_handles_labels()
# COLOR LEGEND (FIRST 30 ITEMS)
col_lgd = plt.legend(h[:30], l[:30], loc='upper left',
bbox_to_anchor=(-0.05, -0.50), fancybox=True, shadow=True, ncol=5)
# SIZE LEGEND (LAST 5 ITEMS)
size_lgd = plt.legend(h[-5:], l[-5:], loc='lower center', borderpad=1.6, prop={'size': 20},
bbox_to_anchor=(0.5,-0.45), fancybox=True, shadow=True, ncol=5)
# ADD FORMER (OVERWRITTEN BY LATTER)
plt.gca().add_artist(col_lgd)
plt.show()
Output
Even consider seaborn's theme with sns.set()
just before plotting:
Thanks a mill @Parfait!!! This looks way much better than what I intended to do. You are quite right that it is helpful to maintain the installs legend, it gives perspective to the graph. Thanks again. However when I ran your code it only showed the installs legend and left out the category legend. Also on my system it still shows triple dots unlike the more elegant single color dot in your output. what can I do about that as well?
– Daniel1234
Nov 23 at 9:33
Weirdly enough when I switched the order by declaringsize_lgd
first and thencol_lgd
theplt.gca().add_artist(size_lgd)
produced the legends. Though it would still be helpful to know how I can change my output from using 3 colored circles to one like yours. All the same thanks for the help. I really appreciate it.
– Daniel1234
Nov 23 at 9:53
Hmmm...I wonder if we are having version issues. I just upgraded both matplotlib and seaborn:pip install --upgrade modulename
and this solution is reproduced. Also, it could be a data issue. Can you reproduce the legend and color issue with my posted data example? If so, try posting a few sample rows of your actual data.
– Parfait
Nov 23 at 15:57
I think it had to do more with some default settings on my system. I was able to trace the settings that needed adjustment and I was able to reproduce the appearance of your output. Both in thesize_lgd
andcol_lgd
I addedmarkerscale=0.3, scatterpoints=1
and it changed the number of appearing scatterpoints from three to one. Thanks again you were really a big help.
– Daniel1234
Nov 24 at 22:23
add a comment |
Actually, that is not a smudge but the size legend for your hue map. Because the bubble sizes (100, 5000)
are so large relative to data, they overlap in that space in legend, creating the "smudge" effect. The default legend combines both color and size legends together.
But rather than remove the size markers as you intend, readers may need to know the range Installs size for bubbles. Hence, consider separating one legend into two legends and use borderpad and prop size to fit the bubbles and labels.
Data (seeded, random data)
categs = ['GAME', 'EDUCATION', 'FAMILY', 'WEATHER', 'ENTERTAINMENT', 'PHOTOGRAPHY', 'LIFESTYLE',
'SPORTS', 'PRODUCTIVITY', 'COMMUNICATION', 'PERSONALIZATION', 'HEALTH_AND_FITNESS', 'FOOD_AND_DRINK', 'PARENTING',
'MAPS_AND_NAVIGATION', 'TOOLS', 'VIDEO_PLAYERS', 'BUSINESS', 'AUTO_AND_VEHICLES', 'TRAVEL_AND_LOCAL',
'FINANCE', 'MEDICAL', 'ART_AND_DESIGN', 'SHOPPING', 'NEWS_AND_MAGAZINES', 'SOCIAL', 'DATING', 'BOOKS_AND REFERENCES',
'LIBRARIES_AND_DEMO', 'EVENTS']
np.random.seed(11222018)
comp_income_inst = pd.DataFrame({'Category': categs,
'Installs': np.random.randint(100, 5000, 30),
'Gross Income': np.random.uniform(0, 30, 30) * 100000
}, columns=['Category', 'Installs', 'Gross Income'])
Graph
fig, ax = plt.subplots(figsize=(13,6))
ax = sns.scatterplot(x="Installs", y="Gross Income", data=comp_income_inst, hue='Category',
palette=sns.color_palette("cubehelix",len(comp_income_inst)),
size='Installs', sizes=(100, 5000), legend='brief', ax=ax)
ax.set(xscale="log", yscale="log")
ax.set(ylabel="Average Income")
ax.set_title("Distribution showing the Earnings of Apps in Various Categoriesn", fontsize=20)
plt.rcParams["axes.labelsize"] = 15
# EXTRACT CURRENT HANDLES AND LABELS
h,l = ax.get_legend_handles_labels()
# COLOR LEGEND (FIRST 30 ITEMS)
col_lgd = plt.legend(h[:30], l[:30], loc='upper left',
bbox_to_anchor=(-0.05, -0.50), fancybox=True, shadow=True, ncol=5)
# SIZE LEGEND (LAST 5 ITEMS)
size_lgd = plt.legend(h[-5:], l[-5:], loc='lower center', borderpad=1.6, prop={'size': 20},
bbox_to_anchor=(0.5,-0.45), fancybox=True, shadow=True, ncol=5)
# ADD FORMER (OVERWRITTEN BY LATTER)
plt.gca().add_artist(col_lgd)
plt.show()
Output
Even consider seaborn's theme with sns.set()
just before plotting:
Actually, that is not a smudge but the size legend for your hue map. Because the bubble sizes (100, 5000)
are so large relative to data, they overlap in that space in legend, creating the "smudge" effect. The default legend combines both color and size legends together.
But rather than remove the size markers as you intend, readers may need to know the range Installs size for bubbles. Hence, consider separating one legend into two legends and use borderpad and prop size to fit the bubbles and labels.
Data (seeded, random data)
categs = ['GAME', 'EDUCATION', 'FAMILY', 'WEATHER', 'ENTERTAINMENT', 'PHOTOGRAPHY', 'LIFESTYLE',
'SPORTS', 'PRODUCTIVITY', 'COMMUNICATION', 'PERSONALIZATION', 'HEALTH_AND_FITNESS', 'FOOD_AND_DRINK', 'PARENTING',
'MAPS_AND_NAVIGATION', 'TOOLS', 'VIDEO_PLAYERS', 'BUSINESS', 'AUTO_AND_VEHICLES', 'TRAVEL_AND_LOCAL',
'FINANCE', 'MEDICAL', 'ART_AND_DESIGN', 'SHOPPING', 'NEWS_AND_MAGAZINES', 'SOCIAL', 'DATING', 'BOOKS_AND REFERENCES',
'LIBRARIES_AND_DEMO', 'EVENTS']
np.random.seed(11222018)
comp_income_inst = pd.DataFrame({'Category': categs,
'Installs': np.random.randint(100, 5000, 30),
'Gross Income': np.random.uniform(0, 30, 30) * 100000
}, columns=['Category', 'Installs', 'Gross Income'])
Graph
fig, ax = plt.subplots(figsize=(13,6))
ax = sns.scatterplot(x="Installs", y="Gross Income", data=comp_income_inst, hue='Category',
palette=sns.color_palette("cubehelix",len(comp_income_inst)),
size='Installs', sizes=(100, 5000), legend='brief', ax=ax)
ax.set(xscale="log", yscale="log")
ax.set(ylabel="Average Income")
ax.set_title("Distribution showing the Earnings of Apps in Various Categoriesn", fontsize=20)
plt.rcParams["axes.labelsize"] = 15
# EXTRACT CURRENT HANDLES AND LABELS
h,l = ax.get_legend_handles_labels()
# COLOR LEGEND (FIRST 30 ITEMS)
col_lgd = plt.legend(h[:30], l[:30], loc='upper left',
bbox_to_anchor=(-0.05, -0.50), fancybox=True, shadow=True, ncol=5)
# SIZE LEGEND (LAST 5 ITEMS)
size_lgd = plt.legend(h[-5:], l[-5:], loc='lower center', borderpad=1.6, prop={'size': 20},
bbox_to_anchor=(0.5,-0.45), fancybox=True, shadow=True, ncol=5)
# ADD FORMER (OVERWRITTEN BY LATTER)
plt.gca().add_artist(col_lgd)
plt.show()
Output
Even consider seaborn's theme with sns.set()
just before plotting:
answered Nov 22 at 22:37
Parfait
49.5k84168
49.5k84168
Thanks a mill @Parfait!!! This looks way much better than what I intended to do. You are quite right that it is helpful to maintain the installs legend, it gives perspective to the graph. Thanks again. However when I ran your code it only showed the installs legend and left out the category legend. Also on my system it still shows triple dots unlike the more elegant single color dot in your output. what can I do about that as well?
– Daniel1234
Nov 23 at 9:33
Weirdly enough when I switched the order by declaringsize_lgd
first and thencol_lgd
theplt.gca().add_artist(size_lgd)
produced the legends. Though it would still be helpful to know how I can change my output from using 3 colored circles to one like yours. All the same thanks for the help. I really appreciate it.
– Daniel1234
Nov 23 at 9:53
Hmmm...I wonder if we are having version issues. I just upgraded both matplotlib and seaborn:pip install --upgrade modulename
and this solution is reproduced. Also, it could be a data issue. Can you reproduce the legend and color issue with my posted data example? If so, try posting a few sample rows of your actual data.
– Parfait
Nov 23 at 15:57
I think it had to do more with some default settings on my system. I was able to trace the settings that needed adjustment and I was able to reproduce the appearance of your output. Both in thesize_lgd
andcol_lgd
I addedmarkerscale=0.3, scatterpoints=1
and it changed the number of appearing scatterpoints from three to one. Thanks again you were really a big help.
– Daniel1234
Nov 24 at 22:23
add a comment |
Thanks a mill @Parfait!!! This looks way much better than what I intended to do. You are quite right that it is helpful to maintain the installs legend, it gives perspective to the graph. Thanks again. However when I ran your code it only showed the installs legend and left out the category legend. Also on my system it still shows triple dots unlike the more elegant single color dot in your output. what can I do about that as well?
– Daniel1234
Nov 23 at 9:33
Weirdly enough when I switched the order by declaringsize_lgd
first and thencol_lgd
theplt.gca().add_artist(size_lgd)
produced the legends. Though it would still be helpful to know how I can change my output from using 3 colored circles to one like yours. All the same thanks for the help. I really appreciate it.
– Daniel1234
Nov 23 at 9:53
Hmmm...I wonder if we are having version issues. I just upgraded both matplotlib and seaborn:pip install --upgrade modulename
and this solution is reproduced. Also, it could be a data issue. Can you reproduce the legend and color issue with my posted data example? If so, try posting a few sample rows of your actual data.
– Parfait
Nov 23 at 15:57
I think it had to do more with some default settings on my system. I was able to trace the settings that needed adjustment and I was able to reproduce the appearance of your output. Both in thesize_lgd
andcol_lgd
I addedmarkerscale=0.3, scatterpoints=1
and it changed the number of appearing scatterpoints from three to one. Thanks again you were really a big help.
– Daniel1234
Nov 24 at 22:23
Thanks a mill @Parfait!!! This looks way much better than what I intended to do. You are quite right that it is helpful to maintain the installs legend, it gives perspective to the graph. Thanks again. However when I ran your code it only showed the installs legend and left out the category legend. Also on my system it still shows triple dots unlike the more elegant single color dot in your output. what can I do about that as well?
– Daniel1234
Nov 23 at 9:33
Thanks a mill @Parfait!!! This looks way much better than what I intended to do. You are quite right that it is helpful to maintain the installs legend, it gives perspective to the graph. Thanks again. However when I ran your code it only showed the installs legend and left out the category legend. Also on my system it still shows triple dots unlike the more elegant single color dot in your output. what can I do about that as well?
– Daniel1234
Nov 23 at 9:33
Weirdly enough when I switched the order by declaring
size_lgd
first and then col_lgd
the plt.gca().add_artist(size_lgd)
produced the legends. Though it would still be helpful to know how I can change my output from using 3 colored circles to one like yours. All the same thanks for the help. I really appreciate it.– Daniel1234
Nov 23 at 9:53
Weirdly enough when I switched the order by declaring
size_lgd
first and then col_lgd
the plt.gca().add_artist(size_lgd)
produced the legends. Though it would still be helpful to know how I can change my output from using 3 colored circles to one like yours. All the same thanks for the help. I really appreciate it.– Daniel1234
Nov 23 at 9:53
Hmmm...I wonder if we are having version issues. I just upgraded both matplotlib and seaborn:
pip install --upgrade modulename
and this solution is reproduced. Also, it could be a data issue. Can you reproduce the legend and color issue with my posted data example? If so, try posting a few sample rows of your actual data.– Parfait
Nov 23 at 15:57
Hmmm...I wonder if we are having version issues. I just upgraded both matplotlib and seaborn:
pip install --upgrade modulename
and this solution is reproduced. Also, it could be a data issue. Can you reproduce the legend and color issue with my posted data example? If so, try posting a few sample rows of your actual data.– Parfait
Nov 23 at 15:57
I think it had to do more with some default settings on my system. I was able to trace the settings that needed adjustment and I was able to reproduce the appearance of your output. Both in the
size_lgd
and col_lgd
I added markerscale=0.3, scatterpoints=1
and it changed the number of appearing scatterpoints from three to one. Thanks again you were really a big help.– Daniel1234
Nov 24 at 22:23
I think it had to do more with some default settings on my system. I was able to trace the settings that needed adjustment and I was able to reproduce the appearance of your output. Both in the
size_lgd
and col_lgd
I added markerscale=0.3, scatterpoints=1
and it changed the number of appearing scatterpoints from three to one. Thanks again you were really a big help.– Daniel1234
Nov 24 at 22:23
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437462%2fhow-do-i-remove-an-attribute-from-the-legend-of-a-scatter-plot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Seaborn: title and subtitle placement
– Diziet Asahi
Nov 22 at 20:45