pce*_*con 8 python blur matplotlib noise
正如问题所说,我正在寻找一种使用Matplotlib绘制模糊点的方法.我不想绘制一组点,然后应用滤镜来模糊整个图像.而不是它,我想绘制一组点,每个点都有一个相关的模糊水平.
先感谢您.
这是另一项工作.您可以使用a在每个位置显示图像而不是标记BboxImage.这样,您可以以任何方式模糊或操纵图像.本教程有更多关于BboxImages的内容.
import matplotlib.pyplot as plt
from scipy import ndimage
from matplotlib.image import BboxImage
from matplotlib.transforms import Bbox, TransformedBbox
import numpy as np
# Create and save an image with just a marker in it
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.plot(0.5,0.5,'*',ms=200)
ax1.set_ylim(0,1)
ax1.set_xlim(0,1)
plt.axis('off')
fig1.savefig('marker.png')
# Read in the same marker image
marker = plt.imread('marker.png')
# New figure and data
fig2 = plt.figure()
ax2 = fig2.add_subplot(111)
x = 8*np.random.rand(10) + 1
y = 8*np.random.rand(10) + 1
sigma = np.arange(10,60,5)
# Blur the marker and image plot the blurred image at each data point.
for xi, yi, sigmai in zip(x,y,sigma):
markerBlur = ndimage.gaussian_filter(marker,sigmai) # Blur the marker image
# Create an BboxImage for the blurred marker and add it to the plot.
bb = Bbox.from_bounds(xi,yi,1,1)
bb2 = TransformedBbox(bb,ax2.transData)
bbox_image = BboxImage(bb2,
norm = None,
origin=None,
clip_on=False)
bbox_image.set_data(markerBlur)
ax2.add_artist(bbox_image)
ax2.set_xlim(0,10)
ax2.set_ylim(0,10)
plt.show()
Run Code Online (Sandbox Code Playgroud)

当你无法做到时,假装它.
import matplotlib.pyplot as plt
import numpy as np
# some random data
x = np.random.random(100)
y = np.random.random(100)
z = np.random.random(100)
# z reflects the amount of defocus at each dot
# if z=0, the point is small (1 pt)
# if z=1, the point is large (50 pt)
# each dot is composed of different layers
fig = plt.figure()
ax = fig.add_subplot(111)
for i in np.arange(.1,1.01,.1):
ax.scatter(x, y, s=(50*i*(z*.9+.1))**2, color=(0,0,0,.5/i/10))
Run Code Online (Sandbox Code Playgroud)
这给出了:

这绝不是完美的,但这些方面的东西可能足以满足您的需求.需要考虑的事项:
所以,这只是一个丑陋的假货.有时他们看起来不够好,有时候不行.
| 归档时间: |
|
| 查看次数: |
1867 次 |
| 最近记录: |