Matplotlib scatter plot with labels11/20/2023 Do you have any suggestions of a better way to display some label/name about a point?Īny guidance or pointers to documentation where I could read up would be appreciated. I'm not sure what to make of this error and would appreciate any help.Īnother question I have is (from trying out changes on the existing plot in the DataCursor thread) that using index of to get back label as I am currently doing will give me a value doesn't exist in list error since the clicked on value may not be exactly same as the value in the list. I want to be able to see the string stored in the list hts on mouseover at the x and y coordinates stored in nov14 and nov21 lists respectively at the same indices. I am getting the following error though: AttributeError: 'CircleCollection' object has no attribute 'get_data' import numpy as np from matplotlib import pyplot from Assembly import AssembleCenterCoordinates def centerPlot (G, A, Values, axissize): coorCenter AssembleCenterCoordinates (G, A) coorCorner G.get ('coor') round numbers to 2 decimal points Values np. # ht_dict has the following format: 'ht1' = where each key is a string and each value is a list of two integersįig.canvas.mpl_connect('pick_event', DataCursor(plt.gca(), hts, nov14, nov21)) My current code is as follows but I have troubles adding a title and axis labels. Textcoords='offset points', ha='right', va='bottom',ībox=dict(boxstyle='round,pad=0.5', fc='yellow', alpha=0.5),Īrrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0') In particular, it would be nice to be able to quickly see the names of the points that are. I would like to be able to see the name of an object when I hover my cursor over the point on the scatter plot associated with that object. Each point on the scatter plot is associated with a named object. Xy=(self.x, self.y), xytext=(self.xoffset, self.yoffset), I am using matplotlib to make scatter plots. Self.annotation = ax.annotate(self.text_template, However, there are two differences: one, I'm making a scatter plot and two, I want to label names for each point and not just the x,y coordinates. I have several thousand points and would like to see their label on mouseover. I am trying to use the DataCursor approach ( ) to label points using matplotlib. set_xticklabels ( XTICKS, fontname = "Lobster Two", size = 15 ) ax. Change the axis limits with ax.setylim() and ax. set_ylabel ( "bill Length (mm)", fontname = "Lobster Two", size = 18, weight = "bold" ) ax. 1.1 Formatting Options Set the title with ax.settitle() Set the axis labels with ax.setylabel() and ax. set_yticklabels ( YTICKS, fontname = "Lobster Two", size = 15 ) ax. set_linewidth ( 2 ) # Customize labels and ticks ax. set_color ( "none" ) # Customize spines color ax. set_ha ( "left" ) # Customize layout - # Hide spines ax. set_title ( "Species" ) legend_title = legend. set_fontsize ( 16 ) # Change default font size # Grab title and customize its appearence. set_fontname ( "Roboto" ) # Change default font text. set_text ( species ) # Set species name text. legend ( loc = ( 0.85, 0.025 ), # bottom-right labelspacing = 1.5, # add space between labels markerscale = 1.5, # increase marker size frameon = False # don't put a frame ) # Iterate through text elements and species names for text, species in zip ( legend. set_title ( "Scatter plot of flipper length vs bill length", loc = "left", ha = "left", fontsize = 24, fontname = "Lobster Two", color = BLUE_DARK, weight = "bold", pad = 10 ) # Add legend - # We store the result of `ax.legend()` for further customizations legend = ax. suptitle ( "Palmer Penguins Data Visualization", x = 0.122, y = 0.975, ha = "left", fontsize = 32, fontname = "Lobster Two", color = BLUE, weight = "bold", ) # Subtitle ax.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |