如何在Python中的散点图中绘制两个变量的颜色?
我有一个具有两个不同变量的数据集,我想用不同的颜色给每个变量,任何人可以帮忙吗?链接到我的数据集:“ https://github.com/mayuripandey/data-analysis/blob/main/word.csv”
import matplotlib.pyplot as plt
import pandas as pd
fig, ax = plt.subplots(figsize=(10, 6))
ax.scatter(x = df['Friends Network-metrics'], y = df['Number of Followers'],cmap = "magma")
plt.xlabel("Friends Network-metrics")
plt.ylabel("Number of Followers")
plt.show()
I have a dataset with two different variables, i want to give colors to each with different color, Can anyone help please? Link to my dataset : "https://github.com/mayuripandey/Data-Analysis/blob/main/word.csv"
import matplotlib.pyplot as plt
import pandas as pd
fig, ax = plt.subplots(figsize=(10, 6))
ax.scatter(x = df['Friends Network-metrics'], y = df['Number of Followers'],cmap = "magma")
plt.xlabel("Friends Network-metrics")
plt.ylabel("Number of Followers")
plt.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不清楚您想在这里做什么。但是,我将提供一个可能对您有所帮助的解决方案。
可以使用
seaborn
在变量上实现颜色。否则,您需要迭代点以设置颜色。或创建一个有条件地输入值的新列。我不知道您的变量是什么,但是您只想将其放入
hue
参数:这可以为您提供这样的视图:
sstatic.net/afnk1.png“ rel =“ nofollow noreferrer 寻找其中一个变量的颜色尺度,您将做以下操作。但是,最大值是如此之大,以至于范围也不会真正有效的视觉效果:
因此您可以调整刻度要查看光图):
Not very clear what you want to do here. But I'll provide a solution that may help you a bit.
Could use
seaborn
to implement the colors on the variables. Otherwise, you'd need to iterate through the points to set the color. Or create a new column that conditionally inputs a color for a value.I don't know what your variable is, but you just want to put that in for the
hue
parameter:This can give you a view like this:
If you were looking for color scale for one of the variables though, you would do the below. However, the max value is so big that the range also doesn't make it really an effective visual:
So you could adjust the scale (I'd also add edgecolors = 'black' as its hard to see the light plots):