英文:
Why do I receive the colors black and yellow on a scatterplot when a run plyplot.scatter where c is equal to a list of ones and zeros?
问题
以下是代码的翻译部分:
import matplotlib.pyplot as plt
x = [65,70,30,80,20,90,10,10,5,85]
y = [30,20,60,10,70,5,80,70,70,10]
temple_type = [1,1,0,1,0,1,0,0,0,1]
plt.scatter(x, y, c=temple_type, edgecolor="black", s=80)
英文:
The code below prints out a scatterplot of black and yellow circles:
import matplotlib.pyplot as plt
x = [65,70,30,80,20,90,10,10,5,85]
y = [30,20,60,10,70,5,80,70,70,10]
temple_type = [1,1,0,1,0,1,0,0,0,1]
plt.scatter(x , y , c=temple_type, edgecolor ="black" , s = 80)
答案1
得分: 1
你收到了与你正在使用的色彩映射(colormap)的高值和低值相对应的颜色。默认情况下,你正在使用"viridis"色彩映射。
你可以使用cmap
参数来更改色彩映射:
import matplotlib.pyplot as plt
x = [65, 70, 30, 80, 20, 90, 10, 10, 5, 85]
y = [30, 20, 60, 10, 70, 5, 80, 70, 70, 10]
temple_type = [1, 1, 0, 1, 0, 1, 0, 0, 0, 1]
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4))
s1 = ax1.scatter(x, y, c=temple_type, edgecolor="black", s=80, cmap="viridis")
fig.colorbar(s1)
s2 = ax2.scatter(x, y, c=temple_type, edgecolor="black", s=80, cmap="Blues")
fig.colorbar(s2)
plt.show()
英文:
You receive the colors corresponding to the high and low values for the colormap you are using. By default you are using the "viridis"
colormap.
You can change the colormap using the cmap
argument:
import matplotlib.pyplot as plt
x = [65, 70, 30, 80, 20, 90, 10, 10, 5, 85]
y = [30, 20, 60, 10, 70, 5, 80, 70, 70, 10]
temple_type = [1, 1, 0, 1, 0, 1, 0, 0, 0, 1]
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4))
s1 = ax1.scatter(x, y, c=temple_type, edgecolor="black", s=80, cmap="viridis")
fig.colorbar(s1)
s2 = ax2.scatter(x, y, c=temple_type, edgecolor="black", s=80, cmap="Blues")
fig.colorbar(s2)
plt.show()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论