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 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. You can do it like this: import matplotlib.pyplot as plt fig plt.figure () ax fig.addsubplot (1, 1, 1) data (0, 2, 3, 5, 5, 5, 9, 7, 8, 6, 6) ax.plot (data, r-, linewidth4) plt.axvline (x5, ymin0, ymax4. 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, First of all, all your labels appear in the same place according to xytext (0.94,0.96). 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: ()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |