Python實(shí)現(xiàn)改變與矩形橡膠的線條的顏色代碼示例
與矩形相交的線條顏色為紅色,其他為藍(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)改變與矩形橡膠的線條的顏色代碼示例的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:
Python學(xué)習(xí)之用pygal畫世界地圖實(shí)例
Python matplotlib畫圖實(shí)例之繪制擁有彩條的圖表
如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!
相關(guān)文章
Python基于pyjnius庫(kù)實(shí)現(xiàn)訪問(wèn)java類
這篇文章主要介紹了Python基于pyjnius庫(kù)實(shí)現(xiàn)訪問(wèn)java類,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07
簡(jiǎn)單的python協(xié)同過(guò)濾程序?qū)嵗a
這篇文章主要介紹了簡(jiǎn)單的python協(xié)同過(guò)濾程序,分享了相關(guān)代碼示例,小編覺(jué)得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01
Python3基礎(chǔ)之list列表實(shí)例解析
這篇文章主要介紹了Python3的list列表用法,這是Python3數(shù)據(jù)類型中非常常見(jiàn)的應(yīng)用,需要的朋友可以參考下2014-08-08

