如何在matplotlib中绘制多个条形图,当我试图多次调用条形函数时,它们重叠,如下图所示,红色的最高值只能看到.如何在x轴上绘制带有日期的多个条形图?
到目前为止,我试过这个:
import matplotlib.pyplot as plt
import datetime
x = [
datetime.datetime(2011, 1, 4, 0, 0),
datetime.datetime(2011, 1, 5, 0, 0),
datetime.datetime(2011, 1, 6, 0, 0)
]
y = [4, 9, 2]
z = [1, 2, 3]
k = [11, 12, 13]
ax = plt.subplot(111)
ax.bar(x, y, width=0.5, color='b', align='center')
ax.bar(x, z, width=0.5, color='g', align='center')
ax.bar(x, k, width=0.5, color='r', align='center')
ax.xaxis_date()
plt.show()
Run Code Online (Sandbox Code Playgroud)
我懂了:

结果应该是这样的,但是日期在x轴上,并且柱子彼此相邻:

我有一个问题 sys.setrecursionlimit()
从python docs这个函数:
设置Python解释器堆栈的最大深度来限制.此限制可防止无限递归导致C堆栈溢出并导致Python崩溃.最高可能的限制取决于平台.当用户具有需要深度递归的程序和支持更高限制的平台时,用户可能需要将限制设置得更高.这应该小心,因为过高的限制可能导致崩溃.
让我们来看看这个无用的递归函数:
def rec(N):
if N==0:
return 1
else:
return rec(N-1);
Run Code Online (Sandbox Code Playgroud)
现在让我们将最大递归设置为100:
sys.setrecursionlimit(100)
Run Code Online (Sandbox Code Playgroud)
如果我尝试rec(99)(100次递归调用),我得到:
RuntimeError: maximum recursion depth exceeded
Run Code Online (Sandbox Code Playgroud)
要计算rec(99)我需要将递归限制设置为105.
为什么会这样?
我正在使用Windows 10并composer已安装.当我尝试laravel使用此命令全局安装安装程序时:
composer global require laravel/installer
[Composer\Downloader\TransportException]
The "https://repo.packagist.org/packages.json" file could not be downloaded:
failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Run Code Online (Sandbox Code Playgroud)
这意味着包没有下载.我没有使用任何代理服务器.Composer诊断结果如下:
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist:
[Composer\Downloader\TransportException] The "http://repo.packagist.org/packages.json" file could not be downloaded: failed to open stream: A connection attempt failed …Run Code Online (Sandbox Code Playgroud) 我可以使用HC-05模块将数据从我的Android手机发送到我的Arduino Uno.我也想将数据从Arduino发送到我的Android手机,我无法做到这一点.
问题:我将使用我的Android应用程序向我的Arduino Uno发送一个0-9的数字,Arduino会将相同的号码发送回我的应用程序,用文字表示.现在,我可以从我的应用程序向我的Arduino发送数字/字母.我需要帮助解决问题的第二部分.
事实上,这是Android问题的完美复制- 从Arduino接收蓝牙数据,但不幸的是,这仍然没有答案.
我使用了 android studio 提供的标签式活动模板,但我无法找到所用不同片段的 id。对于所有三个片段,模板只有一个 .xml 和 .java。我做了一些更改,并为三个片段制作了三个单独的 .xml 和 .java。但是我无法弄清楚如何从 .xml 或在 .java 中为不同的片段设置 id 并且没有 id 我无法执行片段间通信。
python中的许多内置函数不采用关键字参数。例如chr功能。
>>> help(chr)
Help on built-in function chr in module builtins:
chr(i, /)
Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.
Run Code Online (Sandbox Code Playgroud)
尝试将值传递给chr使用关键字参数不起作用。
>>> chr(i=65)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: chr() takes no keyword arguments
Run Code Online (Sandbox Code Playgroud)
我知道/该chr功能的帮助文本中的字符意味着它不会带有关键字参数。
如何定义不包含关键字参数的函数?当然,我想定义一个仅接受位置参数的函数。
这可能会被标记为重复项,但至少这样我会得到答案。我找不到这个问题的StackOverflow答案。
我学到的另一个类似功能是创建一个不带位置参数的函数。
>>> def f(*, a, b):
... print(a, b)
...
>>> f(1, 2)
Traceback (most recent call last):
File "<stdin>", …Run Code Online (Sandbox Code Playgroud) 我有一个列表列表,例如:
[['c', '2', '3', '4', 'd', '1'], ['e', '14', '16', '18', 'f', '1'], etc.]
Run Code Online (Sandbox Code Playgroud)
它们都遵循相同的模式(一个字符串,三个数字字符串,一个字符串,一个数字字符串)。我想将所有数字字符串都转换为整数,但这样做有困难。
I have tried an exception loop, which doesn't seem to be working (I'm not sure why). I know its targeting the sublists as originally I got a value error of int() doesn't recognise base 10 'c' (the first letter in the first element of the sublist.
[['c', '2', '3', '4', 'd', '1'], ['e', '14', '16', '18', 'f', '1'], etc.]
Run Code Online (Sandbox Code Playgroud)
When I print the results with …
我有以下文件结构
\n\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 test.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 sub\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 foo.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 bar.py\nRun Code Online (Sandbox Code Playgroud)\n\n使用测试.py:
\n\n# test.py\nfrom sub import foo\nfoo.test()\nRun Code Online (Sandbox Code Playgroud)\n\n和 foo.py:
\n\n# foo.py\nfrom . import bar\n\ndef test():\n bar.test()\nRun Code Online (Sandbox Code Playgroud)\n\n和 bar.py:
\n\n# bar.py\ndef test():\n print(\'This is a test\')\nRun Code Online (Sandbox Code Playgroud)\n\n从命令行调用 test.py 时效果很好。
\n\nhome/$ python test.py\nThis is a test\nRun Code Online (Sandbox Code Playgroud)\n\n现在我希望能够直接从命令行调用 foo.py 。所以我将 foo.py 更改为:
\n\n# foo.py\nfrom . import bar\n\ndef test():\n bar.test()\n\nif __name__ == \'__main__\':\n test()\nRun Code Online (Sandbox Code Playgroud)\n\n但是当我调用它时它不起作用
\n\n/home$ cd sub\n/home/sub$ python bar.py\nTraceback (most recent call last):\n …Run Code Online (Sandbox Code Playgroud) 我创建了一个Button b背景颜色为黑色.当我点击它时,我希望它的颜色只有在我手指上的时候变为绿色,即我一直关注它.
我正在使用一个库,该库返回一个Python列表。
当我打印该列表时,它看起来像这样:
print(face_locations)
Run Code Online (Sandbox Code Playgroud)
[(92, 254, 228, 118), (148, 661, 262, 547)]
Run Code Online (Sandbox Code Playgroud)
print(type(face_locations))
Run Code Online (Sandbox Code Playgroud)
<class 'list'>
Run Code Online (Sandbox Code Playgroud)
我有一个值字符串:"92 254 228 118;148 661 262 547"。
我想将此字符串转换为相同的数据类型。
到目前为止,我做了什么:
face_locations= "92 254 228 118;148 661 262 547"
face_locations= face_locations.split(";")
for i in range(len(face_locations)):
face_locations[i] = face_locations[i].split(" ")
Run Code Online (Sandbox Code Playgroud)
两者都是列表...但是当我稍后在代码中运行此函数时,出现错误:
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
....do something
Run Code Online (Sandbox Code Playgroud) 我正在练习多态,以下代码返回错误
class Animal:
def talk(self, something):
print(something)
class Dog(Animal):
def talk(self):
super().talk("woof woof")
Bonny = Dog
Bonny.talk()
Run Code Online (Sandbox Code Playgroud)
TypeError: talk() missing 1 required positional argument: 'self'
Run Code Online (Sandbox Code Playgroud)
根据我学到的,邦尼应该是自我论证,所以为什么自我缺失?
创建一个名为list_numbers_in_words(...)的函数,该函数接收一个正整数作为参数,并返回一个列表,该列表包含与每个数字相对应的单词,其顺序与数字中出现的数字相同。例如,以下代码片段:
res = list_numbers_in_words(5438)
print(res)
Run Code Online (Sandbox Code Playgroud)
应该产生输出:
['five', 'four', 'three', 'eight']
Run Code Online (Sandbox Code Playgroud)
代码无效:
def list_numbers_in_words(num):
l = list(num);
single_digits = ["zero", "one", "two", "three",
"four", "five", "six", "seven",
"eight", "nine"];
if (l==1):
print(single_digits[ord(num[0]) - '0']);
return;
x = 0;
while (x < len(num)):
if (l >= 3):
if (ord(num[x]) - 48 != 0):
print(single_digits[ord(num[x]) - 48],
end = " ");
print(tens_power[l - 3], end = " ");
l -= 1;
else:
if (ord(num[x]) - 48 == 1):
sum = (ord(num[x]) - 48 …Run Code Online (Sandbox Code Playgroud) python ×8
android ×3
python-3.x ×3
list ×2
arduino ×1
bluetooth ×1
class-method ×1
composer-php ×1
import ×1
int ×1
java ×1
laravel-5.5 ×1
matplotlib ×1
module ×1
php ×1
polymorphism ×1
recursion ×1