Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set variable point size in matplotlib

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[0], data[1], 'bo', markersize=data[2], label='the data') plt.show() 

The file I'm importing has three columns. Columns 1 and 2 are stored in data[0] and data[1]) are the (x,y) values and I want each point to have a size relative to column 3 (ie: data[2])

I'm using the Canopy IDE by the way.

like image 328
Gabriel Avatar asked May 27 '13 13:05

Gabriel


People also ask

How do I make matplotlib points smaller?

Set the figure size and adjust the padding between and around the subplots. Create random data points, x. Plot x data points using plot() method, with linewidth =0.5 and color="black".

What is matplotlib default marker size?

Marker size is scaled by s and marker color is mapped to c . size in points^2. Default is rcParams['lines. markersize'] ** 2 .


1 Answers

help(plt.plot) shows

  markersize or ms: float          

so it appears plt.plot does not allow the markersize to be an array.

You could use plt.scatter however:

ax1.scatter(data[0], data[1], marker='o', c='b', s=data[2], label='the data') 

PS. You can also verify that plt.plot's markersize must be a float by searching for "markersize" in the official documentation.

like image 83
unutbu Avatar answered Oct 19 '22 11:10

unutbu