我有一个熊猫系列,
这是图表:
我想填充曲线下的区域。问题是调用
plt.fill(y)
Run Code Online (Sandbox Code Playgroud)
输出:
正如在其他答案中看到的,这是因为我们需要向函数发送一个多边形,所以我们必须添加一个 (0,0) 点。(还有一个(lastPoint,0),但在这种情况下它是不必要的)。
然而,建议的解决方案是编写以下代码:
plt.fill([0]+[*range(0,len(y))], [0]+pd.Series.tolist(y))
Run Code Online (Sandbox Code Playgroud)
我拒绝相信这是最好的解决方案。
代码很糟糕,根本不容易阅读,而且我正在丢失信息(x 轴上没有日期):
此外,如果我同时调用绘图和填充(以使红线位于顶部),则会发生错误:
/usr/local/anaconda3/lib/python3.7/site-packages/matplotlib/dates.py in refresh(self)
1446 def refresh(self):
1447 'Refresh internal information based on current limits.'
-> 1448 dmin, dmax = self.viewlim_to_dt()
1449 self._locator = self.get_locator(dmin, dmax)
1450
/usr/local/anaconda3/lib/python3.7/site-packages/matplotlib/dates.py in viewlim_to_dt(self)
1197 'often happens if you pass a non-datetime '
1198 'value to an axis that has datetime units'
-> 1199 .format(vmin))
1200 return num2date(vmin, self.tz), num2date(vmax, self.tz)
1201
ValueError: view limit minimum -36868.15 is …Run Code Online (Sandbox Code Playgroud) 我们可以在SQL(最好是Postgresql)中模仿pandas函数pivot_table吗?
例如,假设我们有一个包含以下 3 列的表:
Name Day Value
John Sunday 6
John Monday 3
John Tuesday 2
Mary Sunday 6
Mary Monday 4
Mary Tuesday 7
Alex Tuesday 1
Run Code Online (Sandbox Code Playgroud)
我想旋转表格,以便索引是名称,列是日期,单元格是值:
names Monday Sunday Tuesday
John 3 6 2
Mary 4 6 7
Alex null null 1
Run Code Online (Sandbox Code Playgroud)
该示例的部分内容取自问题 将 3 列数据框转换为矩阵
为什么下面的代码是错误的?
fun alwaysThrow() {
throw Error("Sorry")
}
fun checkNumber(arg: Int): Int {
if (arg > 10) {
return arg
}
alwaysThrow()
}
fun main() {
try {
checkNumber(20)
} catch (e: Error) {
println("Error caught: ${e.message}")
}
}
Run Code Online (Sandbox Code Playgroud)
该函数checkNumber无法编译并出现错误:
具有块体的函数中需要“返回”表达式(“{...}”)
我不明白为什么,因为过去的任何事情都不会被执行alwaysThrow。
有没有办法告诉编译器?
由于某种原因,这段代码确实可以编译:
fun checkNumber(arg: Int): Int{
if (arg > 10) {
return arg
}
throw Error("Sorry")
}
fun main() {
try {
checkNumber(1)
} catch (e: Error) {
println("Error caught: ${e.message}")
}
}
Run Code Online (Sandbox Code Playgroud) 所以这是我的问题.
我有一个具有一些属性的结构:
struct foo {
const uint8_t propertyA;
int propertyB;
const int propertyC;
typeX propertyD;
typeY propertyE;
};
Run Code Online (Sandbox Code Playgroud)
然后我创建了这个结构的数组,因为我必须代表对象foo的多个实例:
const int foosQuantity = 8;
struct foo foos[foosQuantity] =
{{ .propertyA=0b11001100, .propertyB=0, .propertyC=140, ...},
{ .propertyA=0b11001000, .propertyB=0, .propertyC=150 ...},
//*** foosQuantity-3 MORE TIMES ***//
{ .propertyA=0b11001000, .propertyB=0, .propertyC=150 ...}}
Run Code Online (Sandbox Code Playgroud)
到现在为止,一切似乎都有效.但是,我还没有想过如何将一种类型的属性数组发送到函数.例如,我把这个函数写在一个extern库中,它带有一个属性数组A:
void myFunc(const uint8_t *propertyAs, sizeArray){
//*** DO STUFF ***//
}
Run Code Online (Sandbox Code Playgroud)
我想直接发送我的struct的属性,而不必使用遍历struct数组的for循环并复制元素.
int main(){
//*** STUFF ***//
myFunc(foos.propertyA, foosQuantity);
//*** MORE STUFF ***//
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这可能吗?
area ×1
arrays ×1
c ×1
curve ×1
fill ×1
kotlin ×1
matplotlib ×1
pandas ×1
pivot ×1
pivot-table ×1
postgresql ×1
python ×1
sql ×1
struct ×1