I am plotting many overlapping regions with MatPlotLib, and I would like them to not be opaque. I can reduce the opacity of each region individually by setting alpha=0.2 (or some number <1), but when the regions overlap they become quite dense and almost opaque again. Is there any way to assign the union of these regions one overall opacity? Screen shot attached -- I'd like the whole region to be as transparent as the bottommost shading, and not as dark as it gets at the top.
Thanks!
-Sam
Related
I'm plotting a map with the folium python package and it looks beautiful. However, the free tileset I'm using (the USGS one, listed here as "USGS.USImagery") only serves tiles up to zoom level 16.
I'd like to be able to zoom in closer than that, as I'm plotting some of my own features on top of those tiles at a higher resolution. Is there a way to tell folium to just upscale the level-16 tiles when zooming to anything above 16? I'm aware they will be pixelated, but I'd rather that than blank grey tiles.
See this question: Why empty tiles when zoomed "too much" in Leaflet.js? on gis.stackexchange:
And on the folium documentation:
max_zoom (int, default 18) – Maximum allowed zoom level for this tile layer.
max_native_zoom (int, default None) – The highest zoom level at which
the tile server can provide tiles. If provided you can zoom in past
this level. Else tiles will turn grey.
You have to set the max_native_zoom to 14 (in your example), and the max_zoom to a higher value, which matches your higher resolution features.
If I have an image with a black background on which various colored rectangles are drawn, how can I find them?
The rectangles are empty but with colored edges (each rectangle has different colors), each rectangle intersects at least one other (the sides of different rectangles do not overlap long but cross and the corners of different rectangles do not overlap), moreover they are aligned with the axis (so they cannot be oblique).
I would like to find how many these rectangles are, which is the smallest of all and what is the order of these rectangles (i.e. see which was drawn first up to which which last) identifying them by color. So I would like to find the length of the edges and the vertices (to see which one is smaller). Without import libraries.
So far I have reasoned like this:
for line in range (len (image)):
for column in range (len (line)):
Then I thought about "saving" the colors I encounter in a dictionary, but I don't know how to go on because as the rectangles intersect I'm afraid of working hours on a wrong code.
Can you give me a hand?
This is an example:
https://pasteboard.co/JBHMImK.png
I am generating contour plots (with transparent background) for pH of water on a river, and am overlaying the generated plot on the interactive map using map box. It looks like this:
I want to overlay plot in only on the water area, and not show over the ground area.
In my understanding there should be two ways possible:
1. While generating the image, making that part invisible
2. While overlaying the image, making that part invisible
I have tried finding solution for both but couldn't get a solution. Is there any way to go about it?
Dear stackoverflow community!
I need to plot a 2D-map in python using imshow. The command used is
plt.imshow(ux_map, interpolation='none', origin='lower', extent=[lonhg_all.min(), lonhg_all.max(), lathg_all.min(), lathg_all.max()])
The image is then saved as follows
plt.savefig('rdv_cr%s_cmlon%s_ux.png' % (2097, cmlon_ref))
and looks like
The problem is that when zooming into the plot one can notice that the pixels have different shapes (e.g. different width). This is illustrated in the zoomed part below (taken from the top region of the the first image):
Is there any reason for this behaviour? I input a rectangular grid for my data, but the problem does not have to do with the data itself, I suppose. Instead it is probably something related to rendering. I'd expect all pixels to be of equal shape, but as could be seen they have both different widths as well as heights. By the way, this also occurs in the interactive plot of matplotlib. However, when zooming in there, they become equally shaped all of a sudden.
I'm not sure as to whether
https://github.com/matplotlib/matplotlib/issues/3057/ and the link therein might be related, but I can try playing around with dpi values. In any case, if anybody knows why this happens, could that person provide some background on why the computer cannot display the plot as intended using the commands from above?
Thanks for your responses!
This is related to the way the image is mapped to the screen. To determine the color of a pixel in the screen, the corresponding color is sampled from the image. If the screen area and the image size do not match, either upsampling (image too small) or downsampling (image too large) occurs.
You observed a case of upsampling. For example, consider drawing a 4x4 image on a region of 6x6 pixels on the screen. Sometimes two screen pixels fall into an image pixel, and sometimes only one. Here, we observe an extreme case of differently sized pixels.
When you zoom in in the interactive view, this effect seems to disapear. That is because suddenly you map the image to a large number of pixels. If one image pixel is enlarged to, say, 10 screen pixels and another to 11, you hardly notice the difference. The effect is most apparent when the image nearly matches the screen resolution.
A solution to work around this effect is to use interpolation, which may lead to an undesirable blurred look. To reduce the blur you can...
play with different interpolation functions. Try for example 'kaiser'
or up-scale the image by a constant factor using nearest neighbor interpolation (e.g. replace each pixel in the image by a block of pixels with the same color). Then any blurring will only affect the edges of the block.
I'm using matplotlib for visualizing some data on a world map, and I would like to fill the regions with a custom pattern, which may be of multiple colors.
I have two main patterns that I would like to obtain:
fill each region with stripes, but those stripes have multiple colors and different thickness depending on the region. For example, one region may be totally red, another may be half red and half green, and another may have red and blue lines, but red lines are much thicker than the blue ones.
fill with different colors in a pie-chart sliced fashion: some rays depart from the centroid of the region toward the borders,
More generally, I would like to understand how to draw a custom image and use it as a repeated pattern. Each region I've got is a set of lines, so I can assume that I can compute its centroid, size and borders before drawing the pattern.
For example, I may want to draw an histogram for each region and plot the histogram inside the region, but for doing that I need a general way for using custom images as patterns.
So, how do I do that? I tried looking at matplotlib gallery, but didn't see anything like that.
EDIT: I saw the hatch demo, but as far as I understand, has just one color, and I cannot use custom images in it http://matplotlib.org/examples/pylab_examples/hatch_demo.html