第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

matplotlib 兩條以上曲線之間的填充

matplotlib 兩條以上曲線之間的填充

元芳怎么了 2023-08-08 15:09:58
我想在下面的問(wèn)題中填寫(xiě)3行之間的內(nèi)容。這是代碼:import numpy as npimport matplotlib.pyplot as plt%matplotlib inline# Construct lines# x > 0x = np.linspace(0, 20, 2000)# C1y1 = (36-2*x)/6# C2y2 = (30-5*x)/3# C3y3 = (40-8*x)/2# C4# y4 = 0*x# Make plotplt.plot(x, y1, label=r'$2 x_{1} + 6 x_{2}\leq 36$')plt.plot(x, y2, label=r'$x_{1} + 3 x_{2}\leq 30$')plt.plot(x, y3, label=r'$x_{1} + 2 x_{2}\leq 40$')# plt.plot(x, y4, label=r'$x_{1}, x_{2}\geq 0$')plt.xlim((0, 16))plt.ylim((0, 11))plt.xlabel(r'$x_1$')plt.ylabel(r'$x_2$')# Fill feasible regiony5 = np.minimum(0, 0)y6 = np.maximum(y2, y3)plt.fill_between(x, y1, y2, color='grey', alpha=0.5,                interpolate=True)plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)我想填充下圖中紅色陰影部分(在 y1、y2、y3 和零之間)
查看完整描述

2 回答

?
守候你守候我

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊

https://img1.sycdn.imooc.com//64d1ea980001e15c10340456.jpg

您可以在零和三條曲線的最小值之間進(jìn)行填充:


import numpy as np

import matplotlib.pyplot as plt


x = np.linspace(0, 20, 2000)

y1 = (36 - 2 * x) / 6

y2 = (30 - 5 * x) / 3

y3 = (40 - 8 * x) / 2


plt.plot(x, y1, label=r'$2 x_{1} + 6 x_{2}\leq 36$')

plt.plot(x, y2, label=r'$x_{1} + 3 x_{2}\leq 30$')

plt.plot(x, y3, label=r'$x_{1} + 2 x_{2}\leq 40$')

plt.xlim((0, 16))

plt.ylim((0, 11))

plt.xlabel(r'$x_1$')

plt.ylabel(r'$x_2$')


plt.fill_between(x, y1, y2, color='grey', alpha=0.5,

                 interpolate=True)

plt.fill_between(x, 0, np.min([y1, y2, y3], axis=0), color='red', alpha=0.5, hatch='//',

                 interpolate=True, label='$intersection$')

plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

plt.tight_layout()

plt.show()


查看完整回答
反對(duì) 回復(fù) 2023-08-08
?
犯罪嫌疑人X

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊

注意:

  1. np.vstack([y1, y2, y3])從 3 個(gè)“y”數(shù)組創(chuàng)建一個(gè) 3 行數(shù)組。

  2. ….min(0)計(jì)算每列的最小值,因此它實(shí)際上是 3 個(gè)源數(shù)組中的最小值(對(duì)于較高的x也具有負(fù)值)。

  3. ….clip(min=0)將上述負(fù)數(shù)元素轉(zhuǎn)換為0。

因此,添加到您的代碼中:

plt.fill_between(x, 0, np.vstack([y1, y2, y3]).min(0).clip(min=0),
    color='yellow', alpha=0.5, interpolate=True)

例如在你的第一個(gè)fill_ Between之后。

對(duì)于您的數(shù)據(jù)以及添加了上述指令的代碼,我得到:

https://img1.sycdn.imooc.com//64d1eabc0001eb8803880261.jpg

如果需要,請(qǐng)將填充顏色更改為適合您需要的顏色。



查看完整回答
反對(duì) 回復(fù) 2023-08-08
  • 2 回答
  • 0 關(guān)注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)