我已经制作了两列数据,其中一列是286号作为y量,另一列是286号作为y1-量作为x的函数。我想逐行比较这两列,如果y大于y1,则应以红色绘制,否则将以蓝色绘制。但我得到这个错误: 如果yyy> Y1: ^ IndentationError:预期缩进块
请帮助我!
代码:
import pandas as pd
from astropy.table import Table, Column
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
from pandas import DataFrame
data = pd.read_csv('best match.csv')
s01 = pd.DataFrame(5 + data['Vmag'])
ID = pd.DataFrame(data['MAIN_ID'])
s22 = np.multiply(1/1000,data['Plx_1'])
s02 = np.log10(s22)
s03 = np.multiply(5, s02)
yyy = s01['Vmag']+s03
xxx = np.log10(data['Per'])
y1 = -2.8937*xxx - 1.3073
u = np.multiply(0.2, y1)
for row in yyy:
if yyy > y1:
plt.scatter(xxx, yyy, c='r')
else:
plt.scatter(xxx, yyy, c='b')
plt.ylim(3.5,-0.8)
plt.xlim(-1.85, -0.4)
plt.ylabel('$M_V$')
plt.xlabel('Log(p)')
由于
答案 0 :(得分:1)
答案 1 :(得分:1)
也许建议这样做更紧凑,没有循环:
y_smaller = np.random.rand(20)
y1 = np.random.rand(20)
x = np.arange(20)
y_larger = y_smaller.copy()
y_smaller[y_smaller > y1] = np.nan
y_larger[np.isfinite(y_smaller)] = np.nan
plt.scatter(x, y_smaller, color='blue')
plt.scatter(x, y_larger, color='red')
plt.scatter(x, y1, marker='x', color='gray')
pyplot在绘图时会忽略nan
值,因此这是摆脱数组中不需要的数据的简单方法。
答案 2 :(得分:-1)
peewee
需要看起来像那样