假设我有一个matplotlib轴调用ax,我想设置它的几个属性.目前,我这样做:
ax.set_yscale('log')
ax.set_xlim([0,10])
ax.set_xlabel('some label')
Run Code Online (Sandbox Code Playgroud)
但过了一段时间后它变得乏味.然后我遇到了这个方法:
ax.set(yscale='log', xlim=[0,10], xlabel='some label')
Run Code Online (Sandbox Code Playgroud)
更简洁,但似乎有点无证.我的意思是所有文档都说"是一个tkstyle set命令,传递kwargs来设置属性".
什么是首选或惯用的方式?是set方法API稳定吗?
我有一个numpy 2d阵列[中/大型 - 比如500x500].我想找到它的元素指数的特征值.问题是某些值非常负(-800,-1000等),并且它们的指数下溢(意味着它们非常接近零,因此numpy将它们视为零).无论如何在numpy中使用任意精度?
我梦想的方式:
import numpy as np
np.set_precision('arbitrary') # <--- Missing part
a = np.array([[-800.21,-600.00],[-600.00,-1000.48]])
ex = np.exp(a) ## Currently warns about underflow
eigvals, eigvecs = np.linalg.eig(ex)
Run Code Online (Sandbox Code Playgroud)
我已经搜索了一个gmpy和mpmath的解决方案无济于事.任何想法都会受到欢迎.
我使用matplotib的Axes API来绘制一些数字.我绘制的一条线代表理论预期线.它在原始y和x限制之外没有任何意义.我想要的是matlplotlib在自动缩放限制时忽略它.我以前做的是检查当前限制是什么,然后绘制并重置限制.问题在于,当我绘制第三个图时,限制会与理论线一起重新计算,这真的会扩展图形.
# Boilerplate
from matplotlib.figure import Figure
from matplotlib.backends.backend_pdf import FigureCanvasPdf
from numpy import sin, linspace
fig = Figure()
ax = fig.add_subplot(1,1,1)
x1 = linspace(-1,1,100)
ax.plot(x1, sin(x1))
ax.plot(x1, 3*sin(x1))
# I wish matplotlib would not consider the second plot when rescaling
ax.plot(x1, sin(x1/2.0))
# But would consider the first and last
canvas_pdf = FigureCanvasPdf(fig)
canvas_pdf.print_figure("test.pdf")
Run Code Online (Sandbox Code Playgroud) Jenkins声明性管道中的参数可以是动态的吗?
我希望在运行时通过函数填充选项选项值.以下代码确实生成了一个选项列表,但它们似乎是陈旧的 - 可能是在我第一次运行此代码时生成的.如果AMI列表发生变化,则选择保持不变.我想在每次选择时运行它build with parameters.
def findAMIs() {
// Find relevant AMIs based on their name
def sout = new StringBuffer(), serr = new StringBuffer()
def proc = '/usr/bin/aws --region eu-west-1 ec2 describe-images \
' --owners OWNER --filter Name=name,Values=PATTERN \
' --query Images[*].{AMI:Name} --output text'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(10000)
return sout.tokenize()
}
def AMIs = findAMIs().join('\n')
pipeline {
// a declarative pipeline
agent any
parameters {
choice(name: 'Release',
choices: AMIs)
}
...
}
Run Code Online (Sandbox Code Playgroud)
编辑
我最终使用jenkins-job-builder扩展选择参数.它目前不支持该groovyScript …