-1

I have made two column of data one of them are 286 number as y-amounts and another is 286 numbers as y1-amounts as function of x. I want to compare this two columns one row by one row and if y is larger than y1 it should be plotted in red else it will be plotted in blue. But I get this error: if yyy > y1: ^ IndentationError: expected an indented block

please help me!

The code:

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

Thanks

2
  • 3
    I mean, your code is unreadable right now in the question so it will be difficult to say which part is not indented, please format it Commented Jun 4, 2018 at 4:45
  • When you saw this error, did you try using an English dictionary in order to understand what the word "indentation" means? Commented Dec 19, 2023 at 10:02

3 Answers 3

1

Blocks of code are grouped together by indentation in Python. Any loops, functions, classes, or conditional statements('if' isn't a loop, btw) need to be at an indentation level.

Reference

Fixed Code

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe a suggestion to do this a little more compact and without the loop:

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 ignores nan values when plotting, so this is an easy way to get rid of unwanted data in arrays.

enter image description here

Comments

-1
for row in yyy:
    if yyy > y1:
        plt.scatter(xxx, yyy, c='r')
    else:
        plt.scatter(xxx, yyy, c='b')

Needs to look like that

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.