I am plotting a map with geopandas and I a generate the following pic:
enter image description here
But I want to change the legend icon, is it possible to change for other format, like square, rectangle?
Related
I've been stuck for a few days trying to plot a TIF file over a basemap (Google Maps or Mapbox) using Python. I don't know if this is actually possible because I didn't find examples and nothing very clear about it, the most I found is how to plot vector files (shp) on top of basemaps, but nothing about raster.
I have a raster (rainfall_clipped.tif) that is in EPSG:4326 and I'm trying to plot it on top of a MapBox map using the Contextily package. At first I suspected that it could be a projection problem, but even doing the conversions to EPSG:3857, it didn't work. In the documentation Contextily says that it accepts both projections.
Contextily seems to understand the projections, even because it generates the map with the correct axes, the big problem is that it doesn't plot the TIF file on the map. And it's also reading the raster because it loaded the colorbar with the correct values. I don't know if the layer order is wrong or what else it could be.
Below is the code I am using and then the image that is being generated:
data = rasterio.open("rainfall_clipped.tif")
# Read the bounds
left, bottom, right, top = data.bounds
# Create a figure and axes
fig, ax = plt.subplots(figsize=(10, 10))
# Add the raster data to the plot using imshow
im = ax.imshow(data.read(1), extent=[left, right, bottom, top], cmap="Blues")
# Add a colorbar
fig.colorbar(im, ax=ax)
# Add a basemap using contextily
ctx.add_basemap(ax, crs=data.crs, source=ctx.providers.MapBox(accessToken="my_key", id="mapbox/satellite-v9"))
# Show the plot
plt.show()
This code is generating this image:
Output image
What I'm trying to do is something like below:
Expected image
Any suggestions what I can do?
i would like to know how i can add errorbars to my plot. Im attaching pic of code and plotenter image description here
Have multi-dimension data, for example:
data pic
when i plot x,y chart out. matplot gives the x,y coordinate info at the bottom right corner when one moves the cursor around.
I am trying to add more info to the display, such as info1, info2 etc. on top of the x,y, either at the same corner, or popup when cursor moves on the chart.
Thanks
use libraries Plotly and Cufflinks for interactive charts
Here's a simple solution: use a 3d plot, and use color and size arguments with respect to different values of your other variables. That way, you can display a lot of information very easily.
I have some code that eventually produces a contourf plot at a certain location (lat/lon), like below:
The purple in the image represents the matplotlib plot, which is then overlain on a vector world shapefile. Here, it can be seen that the plot is shifted to the left and up of the location on the vector (blue background). The center location on the vector is the red 'X' and the same coordinates on the matplotlib plot is the red '+'. I first thought this shift was coming from some PyQGIS code, but now I think its the matplotlib commands I have in my Python code.
The commands that I use to create the plot and then save the plot to become a .png image are below:
plt.contourf(Xa,Ya,Result)
plt.grid(color='w')
plt.subplots_adjust(left=0,bottom=0,right=1,top=1,wspace=0,hspace=0)
filename="Results/submerged.png"
plt.savefig(filename, dpi=599, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format=None, transparent=False)
Where Xa and Ya are the grid coordinates and Result is the result that is plotted.
I then take the saved .png file and overlay it on the vector in PyQGIS. I asked a question on stackexchange about the shifted result here, but haven't gotten any responses.
Any suggestions would be helpful!
Using basemap it's easy to plot a set of coordinates, like so:
x, y = m(lons, lats)
m.plot(x, y, 'go')
but would it be possible to use an image instead of the green circle ('go')? I didn't find a direct way of doing this from the documentation.
So, let's clarify this a bit: I'm using a map generated with basemap as a background and would like to plot some .png images on top of it instead of the regular plain markers.
If you want to draw .png images then you should try http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.imshow
You might also be interested in the Matplotlib Basemap toolkit. http://matplotlib.sourceforge.net/basemap/doc/html/
For your reference, I answered a similar question to this the other day: Python Matplotlib Basemap overlay small image on map plot