![]() ![]() ) # Save it! - # Optional: # ax.set_facecolor("white") # set axis background color to white # fig.set_facecolor("white") # set figure background color to white # fig.savefig("plot. text (x, y, country, fontsize = 12 ) ) # Adjust text position and add lines - # 'expand_points' is a tuple with two multipliers by which to expand # the bounding box of texts when repelling them from points # 'arrowprops' indicates all the properties we want for the arrows # arrowstyle="-" means the arrow does not have a head (it's just a line!)Īrrowprops = dict (arrowstyle = "-", lw = 1 ) , Matplotlib is an essential tool for any data scientist or analyst looking to visualize their data. A scatterplot is a type of visualization using Cartesian Coordinates to display two variables for a set of data. ![]() TEXTS = for idx, country in enumerate (COUNTRIES ) : # Only append selected countries if country in COUNTRY_HIGHLIGHT : # This list is passed to `adjust_text()` to adjust the position of # the legends and add connecting lines ![]() # Countries that are going to be highlightedĬOUNTRY_HIGHLIGHT = # Add labels - # Iterate through all the countries in COUNTRIES # `ax.text()` outputs are appended to the `TEXTS` list. # Specify countries - # All the countries, in the order they appear in the datasetĬOUNTRIES = corrupt. Handletextpad = 0.6, # Space between text and marker/lineįrameon = False ) # Set transparency - # Iterate through first five handles and set transparency for i in range ( 5 ) : Handles +=, , label = "y ~ log(x)", color = "#696969", lw = 2 ) ] # Add legend -ībox_to_anchor =, # Located in the top-mid of the figure. Add one annotation Once you have created the dataset and plotted the scatterplot with the previous code, you can use text () function of matplotlib to add annotation. Use either screen units or data units to position a box annotation. Markerfacecolor =REGION_COLS, # marker fill color ) for idx, label in enumerate (REGIONS ) ] # Append a handle for the line A BoxAnnotation is a rectangular box that you can use to highlight specific plot regions. Lw = 0, # there's no line added, just the marker Matplotlibs ax.annotate() method creates. # Create handles - # Region names with linebreaks for the long ones The code section below builds a simple line plot and applies three annotations (three arrows with text) on the plot. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |