Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I'm plotting to utilize the Matplotlib scatter plotter. For the markers, I'd preferably like the framework of a hover with a dot inside. I can accomplish this in the event that I basically plot it twice (once with the diagram on the other hand with the spot) yet then my legend isn't right. So my inquiry is, is there any approach to do this? Or then again am I searching for an answer that doesn't exist? 

Code:

import matplotlib.pyplot as plt

fig1 = plt.figure()

ax1 = fig1.add_subplot(111)

x_data = [0.5, 1, 1.5]

y_data = [0.06, 0.06, 0.01]

ax1.scatter(x_data, y_data, label= 'Example legend entry.', s=80, marker='o', facecolors='none', edgecolors='black')

ax1.scatter(x_data, y_data, label= 'Example legend entry.', s=10, marker='o', color='black')

plt.gcf().subplots_adjust(bottom=0.08, top=0.95, left=0.05, right=0.84)

ax1.legend(loc='center left', bbox_to_anchor=(1, 0.5), fancybox=True, ncol=1, fontsize=17, labelspacing=1)

mng = plt.get_current_fig_manager()

mng.window.showMaximized()

plt.show()

Example plot:

No doubt about it might want something like those markers yet with the capacity to have them like that on the legend (not at all like how it is right now split up into the two sections). 

On the off chance that any additional data or explanation is required, simply inquire. Much appreciated ahead of time for any/all assistance! 

Clarification: I don't know I clarified my objective alright. I realize I can dispose of one of the legends, however, the thing I'm attempting to accomplish is a solitary legend section with the joined marker (for example a hover with a 'spot' inside it). On the off chance that I can't accomplish, at that point yes I'll simply incapacitate the legend for the external circle however might very want to get the marker utilized (which is a mix of two markers) on the plot to likewise be utilized on the legend.

1 Answer

0 votes
by (26.4k points)

I suggest you to use latex marker like below:

ax1.scatter(x_data, y_data, label= 'Example legend entry.', s=80, marker=r'$\odot$', facecolors='none', edgecolors='black')

Then plot the graph only one time.

Are you interested to learn python in detail? Come and join the python certification course and get certified.

Related questions

0 votes
1 answer
+2 votes
3 answers
0 votes
1 answer
asked Nov 30, 2020 in Python by laddulakshana (16.4k points)
0 votes
1 answer
asked Jan 5, 2021 in Python by laddulakshana (16.4k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...