请给我画一个散点图,如附图所示。
我已经尝试了下面的代码,但它不起作用。顺便说一下,这是在蟒蛇里。
hours = [n / 3600 for n in seconds]
fig, ax = plt.subplots(figsize=(8, 6))
## Your code here
ax.plot(hours, fish_counts, marker="x")
ax.set_xlabel("Hours since low tide")
ax.set_ylabel("Jellyfish entering bay over 15 minutes")
ax.legend()[![enter image description here][1]][1]附加图像是输出的外观。谢谢。1:https://i.stack.imgur.com/5KQiz.png
发布于 2022-12-03 16:55:20
要在Python中使用图像中显示的数据和格式创建散点图,可以使用以下代码:
hours = [n / 3600 for n in seconds]
fig, ax = plt.subplots(figsize=(8, 6))
ax.scatter(hours, fish_counts, marker="x", color="red")
ax.set_xlabel("Hours since low tide")
ax.set_ylabel("Jellyfish entering bay over 15 minutes")
ax.legend()这段代码与您提供的代码之间的关键区别在于,它使用scatter()方法来创建散点图,而不是使用plot()方法。scatter()方法允许您为数据点指定标记样式和颜色,这对于匹配图像中的散点图格式是必要的。
通过使用此代码,您应该能够创建一个与图像中显示的格式相匹配的散点图。
https://stackoverflow.com/questions/74668688
复制相似问题