简体   繁体   中英

How to draw a map using python

I want to draw a map using python, not really a map with full information, just a get together of a series of small shapes to reflect land use.

The data is like below

1 2 2 3 3 2
2 3 3 1 1 2
1 1 1 1 3 3
3 3 3 3 4 1

Each number represents one land use type. and their positions in the matrix are their coordinates.

I used VBA to do that before, the whole map consists many small square shapes representing land use, but since the data was so large, it took a long time to generate the map, also delete the map.

My question are :

  1. I wonder in python, is there any more fast way to generate this kind of map, as a whole, not a series of shapes, i think that would be faster??

  2. I have tried using contourf, as below, but it says "out of bounds for axis 1", but actually, I printed X,Y and cordi, they have the same shape, why still out of bounds?

     y = np.arange(0, 4 , 1) x = np.arange(0, 6 , 1) X,Y = np.meshgrid(x,y) # cordi is the matrix containing all the data # pyplot is imported before plt.contourf(X,Y, Cordi[X,Y], 8, alpha=.75, cmap='jet') 

Thank you very much for answering!

What about using imshow , which produces something like a heatmap. Here is an example:

In [1]: import numpy as np
In [2]: import matplotlib.pyplot as plt
In [3]: coord_data = np.array([[1, 2, 2, 3, 3, 2], [2, 3, 3, 1, 1, 2], 
                               [1, 1, 1, 1, 3, 3], [3, 3, 3, 3, 4, 1]])
In [4]: map = plt.imshow(coord_data)
In [5]: plt.colorbar(map)
Out[5]: <matplotlib.colorbar.Colorbar instance at 0x7f3df2559c20>
In [6]: plt.show()

在此处输入图片说明

You can specify the interpolation level using the interpolation keyword ( examples ), and the colors used using the cmap keyword ( example colormaps ).

If you don't use interpolation='nearest' , neighboring data points with the same value will look like contours.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM