不建议使用的警告-mataplotlib库中的where参数

时间:2020-10-17 05:23:17

标签: python matplotlib

Ages = [19,20,21,22,23,24,25,26,27]

python = [23000,30000,40000,50000,60000,70000,80000,90000,100000]
Java  = [15000,20000,25000,35000,40000,50000,90000,100000,300000]


pl.plot(Ages,python,label="Python developer") 
pl.plot(Ages,Java,label="Java developer") 

pl.fill_between(Ages,python,Java,where= (python > Java), alpha=0.5, color="blue" , label="greater than")
pl.fill_between(Ages,python,Java,where= (python < Java), alpha=0.5, color="red" , label="less than")


pl.title("Fill area on line plots")   
pl.legend(loc="upper left")
pl.show()

我正在接受过时警告,并且当python值小于Java值时也没有获得红边。...下面我提到了错误和输出的屏幕截图...

错误:

matplot.py:143: MatplotlibDeprecationWarning: The parameter where must have the same size as x in fill_between(). This will become an error in future versions of Matplotlib.
  pl.fill_between(Ages,python,Java,where= (python > Java), alpha=0.5, color="blue" , label="greater than")
matplot.py:144: MatplotlibDeprecationWarning: The parameter where must have the same size as x in fill_between(). This will become an error in future versions of Matplotlib.
  pl.fill_between(Ages,python,Java,where= (python < Java), alpha=0.5, color="red" , label="less than")

输出:

Output screenshot

1 个答案:

答案 0 :(得分:1)

此弃用警告主要是为了指出import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpClientModule } from '@angular/common/http'; import { UserRoutingModule } from './user-routing.module'; import { UserComponent } from './user.component'; @NgModule({ imports: [ UserRoutingModule, FormsModule, HttpClientModule ], declarations: [UserComponent] }) export class UserModule { } 参数与其他数组没有相同数量的参数。通常,它暗示有害行为。以前,这种错误被忽略了。

对于该图上的每个点,where参数应具有一个where值。

在这种情况下,表达式True/False仅具有一个值,因为它们都是常规的Python列表。要获取单个布尔值的列表,您需要手动python < Java手动创建该列表。或将所有内容更改为numpy数组,并让其vectorization and broadcasting负责创建布尔值数组。

请注意,您需要一个额外的参数[p < j for p, j in zip(python, Java)]来处理其中一个点的值为interpolate=True而另一个点的值为True的线段。

这是将列表更改为numpy数组的代码(False然后还返回一个数组)并设置了python > Java

interpolate=True

resulting plot