Reputation: 1266
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!
Upvotes: 2
Views: 1696
Reputation: 10606
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.
Upvotes: 0