首页 > 编程知识 正文

python散点图代码,python读取表格画散点图

时间:2023-05-04 00:24:38 阅读:9172 作者:2620

I ' mworkingwithaprettysimpleexample.icreatethreescatterplotsonthesamesetofaxes,andeachdatasetiplothasadifferentassociatetededed why is this?

import numpy as np

import matplotlib.pyplot as plt

t=NP.linspace (0,10,100 ) )。

x=NP.random.rand (100,3 ) ) ) ) ) ) )。

y=NP.random.rand (100,3 ) ) ) ) ) ) ) )。

colmaps=['Blues ',' Greys ',' Reds']

forIinrange(3) :

PLT.Scatter(x[:i],y[:i],c=t,cmap=colmaps[i],label=i ) ) ) ) ) ) ) )。

plt.legend (

plt.show () )

thisproducesafigurelikebelow :

iwashopingforthefirstlabeltobeblue,the second to be grey,and the third to be red,so they ' reassociatedwithecolormap,butitlokok

youcansetthelegendcolorsassuch :

import numpy as np

import matplotlib.pyplot as plt

t=NP.linspace (0,10,100 ) )。

x=NP.random.rand (100,3 ) ) ) ) ) ) )。

y=NP.random.rand (100,3 ) ) ) ) ) ) ) )。

colmaps=['Blues ',' Greys ',' Reds']

forIinrange(3) :

PLT.Scatter(x[:i],y[:i],c=t,cmap=colmaps[i],label=i ) ) ) ) ) ) ) )。

plt.legend (

legend=ax.get_legend (

legend.legend handles [0].set _ color (PLT.cm.blues ).8 ) )

legend.legend handles [1].set _ color (PLT.cm.greys ).8 ) )

legend.legend handles [2].set _ color (PLT.cm.reds ).8 ) )

plt.show () )

isetthecolorofeachlegendhandletoaspecificvalueintherespectivecolormap。

ifyoumakethescatterdot ' ssizelargeryoucanseethecolorandassociateindividualdotswiththelegendeasier.ialsosetjustonedotperscatatier rather than the default 3,and set the legend's alpha to 0.5,and alpha of scatter plot to 0.7。

.

forIinrange(3) :

PLT.Scatter(x[:i],y[:i],c=t,cmap=colmaps[i],label=i,s=200,alpha=0.7 ) )。

PLT.legend (标记比例=0.7,scatterpoints=1) )。

legend=ax.get_legend (

legend.legend handles [0].set _ color (PLT.cm.blues ).8 ) )

legend.legend handles [1].set _ color (PLT.cm.greys ).8 ) )

legend.legend handles [2].set _ color (PLT.cm.reds ).8 ) )

legend.get_frame(.set_alpha ) (0.5 ) )。

.

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。