Python實(shí)現(xiàn)改變與矩形橡膠的線條的顏色代碼示例
更新時(shí)間:2018年01月05日 08:41:41 投稿:mengwei
這篇文章主要介紹了Python實(shí)現(xiàn)改變與矩形橡膠的線條的顏色代碼示例,具有一定借鑒價(jià)值,需要的朋友可以參考下
與矩形相交的線條顏色為紅色,其他為藍(lán)色。
演示如下:

實(shí)例代碼如下:
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()
腳本運(yùn)行時(shí)間:(0分0.026秒)
總結(jié)
以上就是本文關(guān)于Python實(shí)現(xiàn)改變與矩形橡膠的線條的顏色代碼示例的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:
Python學(xué)習(xí)之用pygal畫世界地圖實(shí)例
Python matplotlib畫圖實(shí)例之繪制擁有彩條的圖表
如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關(guān)文章
Python基于pyjnius庫實(shí)現(xiàn)訪問java類
這篇文章主要介紹了Python基于pyjnius庫實(shí)現(xiàn)訪問java類,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07
Python3基礎(chǔ)之list列表實(shí)例解析
這篇文章主要介紹了Python3的list列表用法,這是Python3數(shù)據(jù)類型中非常常見的應(yīng)用,需要的朋友可以參考下2014-08-08

