<p>@Raket Makhim写道:</p>
<pre><code>"I'm only getting one colour"
</code></pre>
<p>&;@pault回答:</p>
<pre><code>"Try scaling your colors to the range 0 to 1."
</code></pre>
<p>我已经实现了:</p>
<p><a href="https://i.stack.imgur.com/yERnR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yERnR.png" alt="enter image description here"/></a></p>
<p>(但是,颜色栏的最小值当前为1;我希望能够将其设置为0。我会问一个新问题)</p>
<pre><code>import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from sklearn import preprocessing
df = pd.DataFrame({'A':[1,2,1,2,3,4,2,1,4],
'B':[3,1,5,1,2,4,5,2,3],
'C':[4,2,4,1,3,3,4,2,1]})
# set the Colour
x = df.values
min_max_scaler = preprocessing.MinMaxScaler()
x_scaled = min_max_scaler.fit_transform(x)
df_S = pd.DataFrame(x_scaled)
c1 = df['C']
c2 = df_S[2]
colors = [cm.jet(color) for color in c2]
# Graph
plt.figure()
ax = plt.gca()
for a, b, color in zip(df['A'], df['B'], colors):
circle = plt.Circle((a,
b),
1, # Size
color=color,
lw=5,
fill=False)
ax.add_artist(circle)
plt.xlim([0,5])
plt.ylim([0,5])
plt.xlabel('A')
plt.ylabel('B')
ax.set_aspect(1.0)
sc = plt.scatter(df['A'],
df['B'],
s=0,
c=c1,
cmap='jet',
facecolors='none')
plt.grid()
cbar = plt.colorbar(sc)
cbar.set_label('C', rotation=270, labelpad=10)
plt.show()
</code></pre>