当前位置: 移动技术网 > IT编程>脚本编程>Python > Python实现改变与矩形橡胶的线条的颜色代码示例

Python实现改变与矩形橡胶的线条的颜色代码示例

2018年02月04日  | 移动技术网IT编程  | 我要评论

大壮卦,咱俩没戏19楼,金人庆简历

 与矩形相交的线条颜色为红色,其他为蓝色。

演示如下:

实例代码如下:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.transforms import Bbox
from matplotlib.path import Path

# Fixing random state for reproducibility
np.random.seed(19680801)


left, bottom, width, height = (-1, -1, 2, 2)
rect = plt.Rectangle((left, bottom), width, height, facecolor="#aaaaaa")

fig, ax = plt.subplots()
ax.add_patch(rect)

bbox = Bbox.from_bounds(left, bottom, width, height)

for i in range(12):
  vertices = (np.random.random((2, 2)) - 0.5) * 6.0
  path = Path(vertices)
  if path.intersects_bbox(bbox):
    color = 'r'
  else:
    color = 'b'
  ax.plot(vertices[:, 0], vertices[:, 1], color=color)

plt.show()

脚本运行时间:(0分0.026秒)

总结

以上就是本文关于Python实现改变与矩形橡胶的线条的颜色代码示例的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:

如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网