Question

I am using Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32

I am getting a syntax error stating that it is expecting a indented block. I heard that Python checks white spaces and that they have to be "aligned"? I would appreciate any answers and links. I installed matplotlib and numpy by the way.

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np

def graphRawFX () :
date,bid,ask = np.loadtxt('GPBUSD1d.txt'), unpack=True,
                          delimiter=',',
                          converters={0:mdates.strpdate2num('%Y%m%d%H%M%S') }
fig = plt.figure(figsize=(10,7))
ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)

ax1.plot(date,bid)
ax1.plot(date,ask)

ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
Was it helpful?

Solution

I think you are using the wrong tutorial. Not that it matters in this case, but you are linking to the introduction for Python 3.4.

Your mistake is that you dont indent your code after def graphRawFX():

Try this instead:

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np

def graphRawFX () :
    date,bid,ask = np.loadtxt('GPBUSD1d.txt'), unpack=True,
                 delimiter=',',
                 converters={0:mdates.strpdate2num('%Y%m%d%H%M%S') }
    fig = plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)

    ax1.plot(date,bid)
    ax1.plot(date,ask)

    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))

Note: I believe the number of spaces / tabs you are indenting is irrelevant as long as it is the same for each block, but I'm not quite sure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top