python绘图函数m_Python散点图。m的尺寸和样式

我想我们可以通过一系列补丁来做得更好。

根据文件:This (PatchCollection) makes it easier to assign a color map to a heterogeneous

collection of patches.

This also may improve plotting speed, since PatchCollection will

draw faster than a large number of patches.

假设要以数据单位绘制具有给定半径的圆的散点图:def circles(x, y, s, c='b', vmin=None, vmax=None, **kwargs):

"""

Make a scatter of circles plot of x vs y, where x and y are sequence

like objects of the same lengths. The size of circles are in data scale.

Parameters

----------

x,y : scalar or array_like, shape (n, )

Input data

s : scalar or array_like, shape (n, )

Radius of circle in data unit.

c : color or sequence of color, optional, default : 'b'

`c` can be a single color format string, or a sequence of color

specifications of length `N`, or a sequence of `N` numbers to be

mapped to colors using the `cmap` and `norm` specified via kwargs.

Note that `c` should not be a single numeric RGB or RGBA sequence

because that is indistinguishable from an array of values

to be colormapped. (If you insist, use `color` instead.)

`c` can be a 2-D array in which the rows are RGB or RGBA, however.

vmin, vmax : scalar, optional, default: None

`vmin` and `vmax` are used in conjunction with `norm` to normalize

luminance data. If either are `None`, the min and max of the

color array is used.

kwargs : `~matplotlib.collections.Collection` properties

Eg. alpha, edgecolor(ec), facecolor(fc), linewidth(lw), linestyle(ls),

norm, cmap, transform, etc.

Returns

-------

paths : `~matplotlib.collections.PathCollection`

Examples

--------

a = np.arange(11)

circles(a, a, a*0.2, c=a, alpha=0.5, edgecolor='none')

plt.colorbar()

License

--------

This code is under [The BSD 3-Clause License]

(http://opensource.org/licenses/BSD-3-Clause)

"""

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.patches import Circle

from matplotlib.collections import PatchCollection

if np.isscalar(c):

kwargs.setdefault('color', c)

c = None

if 'fc' in kwargs: kwargs.setdefault('facecolor', kwargs.pop('fc'))

if 'ec' in kwargs: kwargs.setdefault('edgecolor', kwargs.pop('ec'))

if 'ls' in kwargs: kwargs.setdefault('linestyle', kwargs.pop('ls'))

if 'lw' in kwargs: kwargs.setdefault('linewidth', kwargs.pop('lw'))

patches = [Circle((x_, y_), s_) for x_, y_, s_ in np.broadcast(x, y, s)]

collection = PatchCollection(patches, **kwargs)

if c is not None:

collection.set_array(np.asarray(c))

collection.set_clim(vmin, vmax)

ax = plt.gca()

ax.add_collection(collection)

ax.autoscale_view()

if c is not None:

plt.sci(collection)

return collection

scatter函数的所有参数和关键字(除了marker)都将以类似的方式工作。

我写了一个gist包括圆,椭圆和正方形/矩形。如果你想要一个其他形状的集合,你可以自己修改它。

如果要绘制colorbar图,只需运行colorbar(),或将返回的集合对象传递给colorbar函数。

例如:from pylab import *

figure(figsize=(6,4))

ax = subplot(aspect='equal')

#plot a set of circle

a = arange(11)

out = circles(a, a, a*0.2, c=a, alpha=0.5, ec='none')

colorbar()

#plot one circle (the lower-right one)

circles(1, 0, 0.4, 'r', ls='--', lw=5, fc='none', transform=ax.transAxes)

xlim(0,10)

ylim(0,10)

输出:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值