Adding y=x to a matplotlib scatter plot if I haven’t kept track of all the data points that went in

You don’t need to know anything about your data per se. You can get away with what your matplotlib Axes object will tell you about the data. See below: import numpy as np import matplotlib.pyplot as plt # random data N = 37 x = np.random.normal(loc=3.5, scale=1.25, size=N) y = np.random.normal(loc=3.4, scale=1.5, size=N) c = …

Read more

How to improve the label placement in scatter plot

Another option using my library adjustText, written specially for this purpose (https://github.com/Phlya/adjustText). from adjustText import adjust_text np.random.seed(2016) N = 50 scatter_data = np.random.rand(N, 3) fig, ax = plt.subplots() ax.scatter(scatter_data[:, 0], scatter_data[:, 1], c=scatter_data[:, 2], s=scatter_data[:, 2] * 150) labels = [‘ano_{}’.format(i) for i in range(N)] texts = [] for x, y, text in zip(scatter_data[:, 0], …

Read more