如何使用一组数据的平均值创建pcolormesh?

时间:2016-05-31 12:20:16

标签: python matplotlib

如何使用这组数据并使用pcolormesh绘制它?数据如下:

  public class GPSTrackerActivity extends AppCompatActivity implements
    GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener {

private GoogleApiClient mGoogleApiClient;
Location mLastLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
    }

}

protected void onStart() {
    mGoogleApiClient.connect();
    super.onStart();
}

protected void onStop() {
    mGoogleApiClient.disconnect();
    super.onStop();
}

@Override
public void onConnected(Bundle bundle) {
    try {

        mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
                mGoogleApiClient);
        if (mLastLocation != null) {
            Intent intent = new Intent();
            intent.putExtra("Longitude", mLastLocation.getLongitude());
            intent.putExtra("Latitude", mLastLocation.getLatitude());
            setResult(1,intent);
            finish();

        }
    } catch (SecurityException e) {

    }

}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

}

我需要将这些数据绘制成3D pcolormesh matplotlib。我该怎么做呢?如果有人可以帮助我,我会非常感激,因为我真的需要帮助。

1 个答案:

答案 0 :(得分:0)

也许你可以关注这个问题:

http://matplotlib.org/examples/pylab_examples/pcolor_demo.html

http://mlpy.sourceforge.net/docs/3.3/tutorial.html

加载模块:

>>> import numpy as np
>>> import mlpy
>>> import matplotlib.pyplot as plt # required for plotting

加载Iris数据集:

>>> iris = np.loadtxt('iris.csv', delimiter=',')
>>> x, y = iris[:, :4], iris[:, 4].astype(np.int) # x: (observations x attributes) matrix, y: classes (1: setosa, 2: versicolor, 3: virginica)
>>> x.shape
(150, 4)
>>> y.shape
(150, )