我有以下代码:
from mpl_toolkits.axes_grid.axislines import SubplotZero
from matplotlib.transforms import BlendedGenericTransform
import matplotlib.pyplot as plt
import numpy
if 1:
fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
ax.axhline(linewidth=1.7, color="black")
ax.axvline(linewidth=1.7, color="black")
plt.xticks([1])
plt.yticks([])
ax.text(0, 1.05, 'y', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center')
ax.text(1.05, 0, 'x', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center')
for direction in ["xzero", "yzero"]:
ax.axis[direction].set_axisline_style("-|>")
ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
ax.axis[direction].set_visible(False)
x = numpy.linspace(-0.5, 1., 1000)
ax.plot(x, numpy.sin(x*numpy.pi), linewidth=1.2, color="black")
plt.show()
Run Code Online (Sandbox Code Playgroud)
产生以下图像:

与实际图形相比,轴箭头看起来有残留.我如何调整它们的大小,使它们相对于轴的宽度看起来正常.
此外 - 这里很难看到,但箭头的内部是蓝色 - 我如何将其更改为黑色?
我正在做99个Haskell问题:http://www.haskell.org/haskellwiki/H-99:_Ninety-Nine_Haskell_Problems
我可以将模块命名为"Nine.hs",并在该文件的顶部
module Nine where
...
Run Code Online (Sandbox Code Playgroud)
但为了简洁起见,我想写"9.hs"并且有
module 9 where
...
Run Code Online (Sandbox Code Playgroud)
不幸的是,这给了我一个解析错误.有办法吗?
我想用来pygit2结帐分支名称。
例如,如果我有两个分支:masterandnew和HEADis at master,我希望能够做到:
import pygit2
repository = pygit2.Repository('.git')
repository.checkout('new')
Run Code Online (Sandbox Code Playgroud)
甚至
import pygit2
repository = pygit2.Repository('.git')
repository.lookup_branch('new').checkout()
Run Code Online (Sandbox Code Playgroud)
但两者都不起作用,pygit2 文档没有提到如何结帐分支。
在为大学编写作业的过程中,我有一种学习新Haskell monad的快乐乐趣.好极了!!!
我有一个typechecks很好的功能:
compile :: Prog -> State VarsState String
compile prog@(Prog functions) = do
s1 <- sequence (map (translate_func 0) [get_function prog name | name <- [func_name func | func <- functions]])
return $ trace ("here's the program: \n" ++ show prog) $ concat $ s1
Run Code Online (Sandbox Code Playgroud)
但当这个其他功能:
maybe_compile_prog ::
MaybeOK Prog -> String -> IO ()
maybe_compile_prog (Error msg) _ = do
putStrLn ("error: " ++ msg)
maybe_compile_prog (OK prog) modulename = do
s1 <- compile prog
writeFile (modulename …Run Code Online (Sandbox Code Playgroud) 在 Jenkins 中,您可以使用 Job DSL 轻松创建列表视图
listView("myView") {
jobs {
regex(".*")
}
}
Run Code Online (Sandbox Code Playgroud)
但是如果您尝试在文件夹中创建列表视图,则会创建文件夹但不会创建视图
folder("someFolder")
listView("someFolder/myView") {
jobs {
regex(".*")
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我有一个迭代函数phi,它多次调用自己以返回正确的结果.
def phi(n, primes, phis):
Run Code Online (Sandbox Code Playgroud)
其中primes是素数列表,1 <n <10,000,000,phis是n的相同范围内的总值列表.
在Python中执行此操作是否代价高昂?我的猜测是它不会花费太多,因为我们处理Python中的指针所以所有会传递的是指针?但是使用此功能,即使POINTERS也会传递很多(读取:sh ## load).这在计算上是否昂贵?
我正在为编程实践做一个项目欧拉问题,以便自我教学.我非常清楚如何以数学方式解决问题,以及如何以编程方式进行.
但是,我必须提出一些疯狂的代码才能做到这一点; 100个嵌套循环和Python搞笑地引发了这个错误,并且可能正确地提出了100个级别的缩进:
IndentationError: too many levels of indentation
tally = 0
ceiling = 100
for integer_1 in range(0, 100, 1):
for integer_2 in range(0, 100 - integer_1, 2):
for integer_3 in range(0, 100 - integer_1 - integer_2, 3):
for integer_4 ....
for integer_5 ....
etc.
etc.
all the way to integer_100
Run Code Online (Sandbox Code Playgroud)
我已经通过谷歌寻找解决方案,但这个问题是如此罕见,它几乎没有关于这个主题的文献,我只能找到这个其他堆栈溢出问题(Python IndentationError:太多级别的缩进),我找不到很多有用的我的问题.
我的问题是 - 有没有办法采取我的解决方案,找到一些解决方法或以一种有效的方式重构它?我真的很难过.
编辑:
感谢nneonneo的回答,我能够解决这个问题.我的代码仅供将来参考,以寻找正确重构代码的方法.
from time import time
t = time()
count_rec_dict = {}
# for finding …Run Code Online (Sandbox Code Playgroud) 我正在大学学习Haskell - 这是我在业余时间做过的一个研讨会问题,你可能会猜到我正在努力解决Haskell中的类型问题.我已经完成了这个问题,但是没有答案发表但我仍然非常怀疑这是否是最好的方法.
以下是问题中提供的HTML的基本表示
type HTML = [HTML_element]
data HTML_element
= HTML_text String
| HTML_font Font_tag HTML
| HTML_p HTML
| HTML_ul [HTML]
| HTML_ol [HTML]
data Font_tag = Font_tag (Maybe Int) (Maybe String) (Maybe Font_color)
data Font_color
= Colour_name String
| Hex Int
| RGB Int Int Int
Run Code Online (Sandbox Code Playgroud)
该问题要求构造一个Haskell函数'num_font_tags',它将计算这种HTML表示中的font_tag的所有实例.接下来是我的回答,这让我花了整整一个小时的时间将我的头贴在墙上,但它编译得很好,我认为这是一个解决方案:
num_font_tags :: HTML -> Int
num_font_tags [] = 0
num_font_tags (x:xs) = num_font_tag_single x + num_font_tags xs
num_font_tags_list :: [HTML] -> Int
num_font_tags_list [] = 0
num_font_tags_list (x:xs) = num_font_tags …Run Code Online (Sandbox Code Playgroud) 我有一个功能
import System.Exit
exit_and_report_type_mismatch :: String -> IO ExitCode
exit_and_report_type_mismatch error_message = do
putStrLn error_message
exitFailure
Run Code Online (Sandbox Code Playgroud)
和另一部分像这样
interpret_expr :: Vars -> Expr -> Val
interpret_expr vars (Plus (ConsE _ _) (NumE _)) = exit_and_report_type_mismatch "Type Error: Can only concatenate list (not int) to list"
Run Code Online (Sandbox Code Playgroud)
Haskell向我抱怨它期待类型Val(我定义的另一种数据类型),但实际上它接收类型IO Exitcode.足够公平 - exit_and_report_mismatch返回的IO ExitCode不是Val.
如何从"exit_and_report_type_mismatch"中完全中止Haskell程序?我已经阅读了一些关于Haskell异常的内容,但是解释要么没有意义,要么提到必须从main函数调用ExitWith,这不是一个选项.
我有以下代码:
from mpl_toolkits.axes_grid.axislines import SubplotZero
from matplotlib.transforms import BlendedGenericTransform
import matplotlib.pyplot as plt
import numpy
if 1:
fig = plt.figure(1)
ax = SubplotZero(fig, 111)
fig.add_subplot(ax)
ax.axhline(linewidth=1.7, color="black")
ax.axvline(linewidth=1.7, color="black")
plt.xticks([1])
plt.yticks([])
ax.text(0, 1.05, 'y', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center')
ax.text(1.05, 0, 'x', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center')
for direction in ["xzero", "yzero"]:
ax.axis[direction].set_axisline_style("-|>")
ax.axis[direction].set_visible(True)
for direction in ["left", "right", "bottom", "top"]:
ax.axis[direction].set_visible(False)
x = numpy.linspace(-1, 1, 10000)
ax.plot(x, numpy.tan(2*(x - numpy.pi/2)), linewidth=1.2, color="black")
plt.ylim(-5, 5)
plt.savefig('graph.png')
Run Code Online (Sandbox Code Playgroud)
生成此图表:

正如您所看到的,不仅绘制了tan图,而且还添加了一部分线来连接tan图的渐近区域,其中渐近线通常是渐近线.
是否有一些内置的方法可以跳过该部分?或者我是否会绘制由渐近线限定的棕褐色的不相交域(如果你理解我的意思)?