Ожидается отступ блока - PullRequest
       21

Ожидается отступ блока

0 голосов
/ 27 декабря 2018

После запуска этого кода, я получаю это исключение, и я не нашел места, чтобы исправить это должным образом

import networkx as nx
from networkx.algorithms import bipartite
import numpy as np
from pandas import DataFrame, concat
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit 
import ast
import csv
import sys

def plot_degree_dist(G):
in_degrees = G.in_degree()
in_degrees=dict(in_degrees)
in_values = sorted(set(in_degrees.values()))
in_hist = [in_degrees.values().count(x) for x in in_values]
plt.figure() 
plt.grid(True)
plt.loglog(in_values, in_hist, 'ro-') 
plt.plot(out_values, out_hist, 'bv-') 
plt.legend(['In-degree', 'Out-degree'])
plt.xlabel('Degree')
plt.ylabel('Number of nodes')
plt.title('network of places in Cambridge')
#plt.xlim([0, 2*10**2])

Я ожидаю получить правильный график, но все, что я получаю, это предупреждение

  File "<ipython-input-32-f89b896484d7>", line 2
    in_degrees = G.in_degree()
             ^
IndentationError: expected an indented block

1 Ответ

0 голосов
/ 27 декабря 2018

Python использует правильные отступы для идентификации функциональных блоков.Этот код должен работать:

import networkx as nx
from networkx.algorithms import bipartite
import numpy as np
from pandas import DataFrame, concat
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit 
import ast
import csv
import sys

def plot_degree_dist(G):
    in_degrees = G.in_degree()
    in_degrees=dict(in_degrees)
    in_values = sorted(set(in_degrees.values()))
    in_hist = [in_degrees.values().count(x) for x in in_values]
    plt.figure() 
    plt.grid(True)
    plt.loglog(in_values, in_hist, 'ro-') 
    plt.plot(out_values, out_hist, 'bv-') 
    plt.legend(['In-degree', 'Out-degree'])
    plt.xlabel('Degree')
    plt.ylabel('Number of nodes')
    plt.title('network of places in Cambridge')
    #plt.xlim([0, 2*10**2])

В основном просто сделайте отступ в 2 или 4 пробела в соответствии с вашими требованиями стиля.

...