我想将x轴ticklabel更改为自定义字符串。
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import matplotlib.pyplot as plt
def pushButtonClicked(self):
code = self.lineEdit.text()
x=["one","two","three"]
l=[1,2,3]
y=[2,3,4]
ax = self.fig.add_subplot(111)
print(1)
ax.plot(l, y, label='DeadPopulation')
ax.xticks(l,x)
print(IntroUI.g_sortArrayDeadcnt)
ax.legend(loc='upper right')
ax.grid()
self.canvas.draw()
Run Code Online (Sandbox Code Playgroud)
尽管搜索了许多站点并找到了许多代码示例,但我无法解决此问题。我的代码有什么问题?
JSON
<script>
var data2sales=
[{
"key": "Owners",
"bar": true,
"values": [
[1490400000000, 1591, "", "", ""],
[1490486400000, 1924, "#2B6A94", "", ""],
[1490572800000, 1982, "", "", ""],
[1490659200000, 1606, "", "", ""]]
}]
</script>
Run Code Online (Sandbox Code Playgroud)
我在 Python 中获取 Json 的代码
notices = str(soup.select('script')[30])
split_words=notices.split('var data2sales= ')
split_words=split_words[1]
temp=split_words[44:689]
temp = 'var data2sales= {' +temp + '}'
print(temp)
newDict = json.loads((temp))
print(newDict)
Run Code Online (Sandbox Code Playgroud)
我是 Python 中 BeautifulSoup 的新手,我正在尝试dict从 BeautifulSoup 中提取一个。正如你在我的代码中看到的,我用 python 重新制作了 JSON 代码并保存在 newDict 变量中。但它不起作用。有没有人可以教我,我怎样才能提取那个 JSON 代码?谢谢你。