Python v / s MATLAB中的散点图

时间:2018-06-19 23:09:06

标签: python scatter

我有两个矩阵-D,c-分别为100x2和100x1。 c仅包含1,-1。在MATLAB中,我有scatter(D(c==1,1),D(c==1,2),'r');

当我为Python尝试plt.scatter(D(c==1,1),D(c==1,2),c='r')(未显示导入)时,它给出一个错误-'numpy.ndarray'对象不可调用。

如何在Python中访问c索引?

1 个答案:

答案 0 :(得分:1)

如果我错了,请更正,但是如果我没记错的话,在MATLAB中,写public partial class LoginPage : ContentPage { public LoginPage() { InitializeComponent(); } List<string> user = new List<string>(); List<string> pass = new List<string>(); public void btnLogin_Clicked(object sender, EventArgs e) { //Read the txt StreamReader sr = new StreamReader("Logins.txt"); string line = ""; //Read every line until there is nothing in the next line while ((line = sr.ReadLine()) != null) { //Grab items within new lines separated by a space and chuck them into their array string[] components = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); user.Add(components[0]); pass.Add(components[0]); } //Check entries are on the same line and match if (user.Contains(txtUsername.Text) && pass.Contains(txtPassword.Text) && Array.IndexOf(user.ToArray(), txtUsername.Text) == Array.IndexOf(pass.ToArray(), txtPassword.Text)) { Navigation.PushModalAsync(new HomeScreen()); } else DisplayAlert("Error", "The username or password you have entered is incorrect", "Ok"); } private void Cancel_Clicked(object sender, EventArgs e) { Navigation.PushModalAsync(new MainPage()); } } 相当于说:

“数组'D'的第一列的所有行,其中数组'c'在同一行上的值为1。”

因此,从本质上讲,您想使用c过滤D。

翻译成Python,看起来非常相似:

D(c==1,1)

提醒一下,在Python中,索引从0开始,切片/索引列表用方括号(plt.scatter(D[0][c==1],D[1][c==1],color='r') some_list(some_index)`)完成。