Python散点图.标记的大小和样式 [英] Python scatter plot. Size and style of the marker
问题描述
我有一组要显示为散点图的数据.我希望将每个点绘制为大小为dx
的正方形.
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')
问题是散布函数读取的大小s
以点^ 2为单位.我想要的是用面积dx ^ 2的正方形表示每个点,其中该面积以真实"单位(绘图单位)表示.希望您能明白这一点.
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?
推荐答案
从用户数据坐标系转换为显示坐标系.
Translate from user data coordinate system to display coordinate system.
并使用edgecolors ='none'绘制没有轮廓的面孔.
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')
这篇关于Python散点图.标记的大小和样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!