![]() ![]() Depending on the points, you may have to play with the xytext values to get better placements.It probably would have been less confusing if we'd used a fixed data table or a random seed. If you are trying to reproduce this example and your plots don't have the points in the same place as any of ours, it may be because the DataFrame was using random values. ![]() Originally it used the same: fig, ax = plt.subplots()Īs the other posts to expose the axes, however this is unnecessary and makes the: import matplotlib.pyplot as plt Syntax: ( x, y, s) Parameters: x, y : scalars The position to place the text. apply(), and includes the nicer-looking annotations (I thought the color scale was a bit overkill and couldn't get the colorbar to go away): ax = df.plot('x', 'y', kind='scatter', s=50 ) In single-point annotation we can use and mention the x coordinate of the scatter point and y coordinate + some factor so that text can be distinctly visible from the plot, and then we have to mention the text. Here was an alternative that avoids the loop using. The only thing that bothered me is that I don't like pulling data out of DataFrames to then loop over them. I found the previous answers quite helpful, especially LondonRob's example that improved the layout a bit. Xytext=(10,-5), textcoords='offset points',įamily='sans-serif', fontsize=18, color='darkslategrey') Or, since that looks incredibly ugly, you can beautify things a bit pretty easily: from matplotlib import cmĭf.plot('x', 'y', kind='scatter', ax=ax, s=120, linewidth=0, import numpy as np import matplotlib.pyplot as plt from matplotlib.lines import Line2D points np.ones(3) Draw 3 points for each line. Also refer to the Marker filling-styles and Marker Path examples. For a list of all markers see the matplotlib.markers documentation. Here's a (very) slightly slicker version of Dan Allan's answer: import matplotlib.pyplot as pltĭf = pd.DataFrame(,įinally, if you're in interactive mode you might need to refresh the plot: () Reference for filled-, unfilled- and custom marker types with Matplotlib. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |