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 Matplotlib Cursor - How to Add a Cursor and Annotate Your Plot This article explains how to insert a cursor to your plot, how to customize it and how to store the values that you selected on the plot window. 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 ) 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. 4 Answers Sorted by: 58 Heres a (very) slightly slicker version of Dan Allans answer: import matplotlib. 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, 3 Answers Sorted by: 9 As jkalden suggested, annotate would solve your problem. 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: () provides a simple way of adding a slope marker by specifying the origin of the marker (normally, the left-most corner of the.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |