Python scatter plot. Size and style of the marker

Brian picture Brian · Jan 31, 2012 · Viewed 96.1k times · Source

I have a set of data that I want to show as a scatter plot. I want each point to be plotted as a square of size dx.

          x = [0.5,0.1,0.3]
          y = [0.2,0.7,0.8]
          z = [10.,15.,12.]
          dx = [0.05,0.2,0.1]

          scatter(x,y,c=z,s=dx,marker='s')

The problem is that the size s that the scatter function read is in points^2. What I'd like is having each point represented by a square of area dx^2, where this area is in 'real' units, the plot units. I hope you can get this point.

I also have another question. The scatter function plots the markers with a black border, how can I drop this option and have no border at all?

Answer

remosu picture remosu · Jan 31, 2012

Translate from user data coordinate system to display coordinate system.

and use edgecolors='none' to plot faces with no outlines.

import numpy as np

fig = figure()
ax = fig.add_subplot(111)
dx_in_points = np.diff(ax.transData.transform(zip([0]*len(dx), dx))) 
scatter(x,y,c=z,s=dx_in_points**2,marker='s', edgecolors='none')