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?

huangapple go评论63阅读模式
英文:

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()

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?

英文:

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()

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?

huangapple
  • 本文由 发表于 2023年6月6日 10:09:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76411015.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定