2

I'm running into problems with a simple Python program for plotting maps with the matplotlib and Basemap. I use example code from the Basemap website:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
m = Basemap(width=12000000,height=9000000,projection='lcc',
            resolution=None,lat_1=45.,lat_2=55,lat_0=50,lon_0=-107.)
m.shadedrelief()
plt.show()

The program crashed and I got the following message:

Segmentation fault (core dumped)

Very interesting is that changing the next-to-last line to:

m.etopo()

causes the program to plot a map. I don't know where to find the error. Is it matplotlib? Is it basemap? Is it Python? My system? Can anybody help?

My versions:

Python 2.7.3
matplotlib: 1.3.1
basemap version: 1.0.7
numpy version: 1.6.1
Linux: Ubuntu 12.04 / 64 bit

Thanx a lot!

3
  • 1
    I am not familiar with the mpl toolkit, but it looks like your map is pretty big. Maybe try a smaller map and see if you can make it through the program as there may be a memory allocation issue, notwithstanding the issue that your are running on a x64 bit system. Commented Feb 3, 2014 at 15:30
  • I am seeing the same thing.. Commented May 13, 2014 at 7:50
  • 1
    Hello, thanks for your replies. But that's not the problem, because testing a smaller map cause the same problem! Regards, John Commented May 20, 2014 at 18:10

1 Answer 1

0

Im my case, compiling and executing the imshow-example in the examples folder helped to find the bug.

imshow.cpp

#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include "../matplotlibcpp.h"

using namespace std;
namespace plt = matplotlibcpp;

int main()
{
    // Prepare data
    int ncols = 500, nrows = 300;
    std::vector<float> z(ncols * nrows);
    for (int j=0; j<nrows; ++j) {
        for (int i=0; i<ncols; ++i) {
            z.at(ncols * j + i) = std::sin(std::hypot(i - ncols/2, j - nrows/2));
        }
    }

    const float* zptr = &(z[0]);
    const int colors = 1;

    plt::title("My matrix");
    plt::imshow(zptr, nrows, ncols, colors);

    // Show plots
    plt::save("imshow.png");
    std::cout << "Result saved to 'imshow.png'.\n";
}

In my case, I tried to plot some unallocated memory region.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.