I want to set a variable marker size in a scatter plot. This is my code:
import numpy as np import matplotlib.pyplot as plt from os import getcwd from os.path import join, realpath, dirname mypath = realpath(join(getcwd(), dirname(__file__))) myfile = 'b34.dat' data = np.loadtxt(join(mypath,myfile), usecols=(1,2,3), unpack=True) fig = plt.figure() ax1 = fig.add_subplot(111) ax1.plot(data, data, 'bo', markersize=data, label='the data') plt.show()
The file I'm importing has three columns. Columns 1 and 2 are stored in
data) are the
(x,y) values and I want each point to have a size relative to column 3 (ie:
I'm using the Canopy IDE by the way.
markersize or ms: float
so it appears
plt.plot does not allow the markersize to be an array.
You could use
ax1.scatter(data, data, marker='o', c='b', s=data, label='the data')
PS. You can also verify that
markersize must be a float by searching for "markersize" in the official documentation.