
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 In matplotlib, you can add a different scatter point for each country (i.e. 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. I found the previous answers quite helpful, especially LondonRob's example that improved the layout a bit. import pandas as pd import numpy as np matplotlib inline import.
Scatter plot matplotlib dataframe how to#
Xytext=(10,-5), textcoords='offset points',įamily='sans-serif', fontsize=18, color='darkslategrey') A step-by-step Python code example that shows how to create a scatter plot in Python. 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, 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: ()
