I would like to group my 2 marker cluster layers, where one is reliant on the other by providing a separate styling. Hence the second one is set as control=False.
Nevertheless, I want to have it disappear when the first one is switched off.
Along with the new Python folium issue v.0.14 I found, that the new feature has been provided, which potentially could resolve my issue:
https://github.com/ikoojoshi/Folium-GroupedLayerControl
Allow only one layer at a time in Folium LayerControl
and I've applied the following code:
df = pd.read_csv("or_geo.csv")
fo=FeatureGroup(name="OR")
or_cluster = MarkerCluster(name="Or", overlay=True, visible=True).add_to(map)
or_status = MarkerCluster(overlay=True,
control=False,
visible=False,
disableClusteringAtZoom=16,
).add_to(map)
GroupedLayerControl(
groups={'OrB': or_cluster, 'OrC': or_status},
collapsed=False,
).add_to(map)
and the console throws the following error:
TypeError: 'MarkerCluster' object is not iterable
How could I switch off 2 layer groups at once?
UPDATE:
The answer below provides the code, which seems to work but not in the way I need.
df = pd.read_csv("or_geo.csv")
fo=FeatureGroup(name="Or",overlay = True)
or_cluster = MarkerCluster(name="Or").add_to(map)
or_status = MarkerCluster(control=False,
visible=True,
disableClusteringAtZoom=16,
).add_to(map)
# definition of or_marker
# definition of or_stat_marker
or_cluster.add_child(or_marker)
or_status.add_child(or_stat_marker)
GroupedLayerControl(
groups={"Or": [or_cluster, or_status]},
collapsed=False,
exclusive_group=False,
).add_to(map)
I have a separate box instead, but what is worst I can just switch between one layer and another whereas I would like to have them reliant on the main group. The exclusive_groups option allows me to untick both of them but I am looking for something, which would allow me to switch off two of them at once (place the thick box on the major group instead). Is it possible to have something like this?
Try passing your markerclusters as a list to the GroupedLayerControl, not one by one. This is described here:
https://nbviewer.org/github/chansooligans/folium/blob/plugins-groupedlayercontrol/examples/plugin-GroupedLayerControl.ipynb
GroupedLayerControl(
groups={'OrB': [or_cluster, or_status]},
collapsed=False,
).add_to(map)
Update I
I see what you mean, that was definitely nonsense as it splits groups instead of joining them. so, back to topic
We had a similar discussion here and I am still convinced that the FeatureSubGroup should solve this issue. I use it in exact that way that I enable/disable a MarkerCluster in the legend and multiple FeatureGroupSubGroups (which are added not to the map but to the MarkerCluster) appear/disappear. Perhaps you try that again
Related
I have been trying to make a figure using plotly that combines multiple figures together. In order to do this, I have been trying to use the make_subplots function, but I have found it very difficult to have the plots added in such a way that they are properly formatted. I can currently make singular plots (as seen directly below):
However, whenever I try to combine these singular plots using make_subplots, I end up with this:
This figure has the subplots set up completely wrong, since I need each of the four subplots to contain data pertaining to the four methods (A, B, C, and D). In other words, I would like to have four subplots that look like my singular plot example above.
I have set up the code in the following way:
for sequence in sequences:
#process for making sequence profile is done here
sequence_df = pd.DataFrame(sequence_profile)
row_number=1
grand_figure = make_subplots(rows=4, cols=1)
#there are four groups per sequence, so the grand figure should have four subplots in total
for group in sequence_df["group"].unique():
figure_df_group = sequence_df[(sequence_df["group"]==group)]
figure_df_group.sort_values("sample", ascending=True, inplace=True)
figure = px.line(figure_df_group, x = figure_df_group["sample"], y = figure_df_group["intensity"], color= figure_df_group["method"])
figure.update_xaxes(title= "sample")
figure.update_traces(mode='markers+lines')
#note: the next line fails, since data must be extracted from the figure, hence why it is commented out
#grand_figure.append_trace(figure, row = row_number, col=1)
figure.update_layout(title_text="{} Profile Plot".format(sequence))
grand_figure.append_trace(figure.data[0], row = row_number, col=1)
row_number+=1
figure.write_image(os.path.join(output_directory+"{}_profile_plot_subplots_in_{}.jpg".format(sequence, group)))
grand_figure.write_image(os.path.join(output_directory+"grand_figure_{}_profile_plot_subplots.jpg".format(sequence)))
I have tried following directions (like for example, here: ValueError: Invalid element(s) received for the 'data' property) but I was unable to get my figures added as is as subplots. At first it seemed like I needed to use the graph object (go) module in plotly (https://plotly.com/python/subplots/), but I would really like to keep the formatting/design of my current singular plot. I just want the plots to be conglomerated in groups of four. However, when I try to add the subplots like I currently do, I need to use the data property of the figure, which causes the design of my scatter plot to be completely messed up. Any help for how I can ameliorate this problem would be great.
Ok, so I found a solution here. Rather than using the make_subplots function, I just instead exported all the figures onto an .html file (Plotly saving multiple plots into a single html) and then converted it into an image (HTML to IMAGE using Python). This isn't exactly the approach I would have preferred to have, but it does work.
UPDATE
I have found that plotly express offers another solution, as the px.line object has the parameter of facet that allows one to set up multiple subplots within their plot. My code is set up like this, and is different from the code above in that the dataframe does not need to be iterated in a for loop based on its groups:
sequence_df = pd.DataFrame(sequence_profile)
figure = px.line(sequence_df, x = sequence_df["sample"], y = sequence_df["intensity"], color= sequence_df["method"], facet_col= sequence_df["group"])
Although it still needs more formatting, my plot now looks like this, which is works much better for my purposes:
I have a basic SQL script which pulls data from MySQL , adds it to a dataframe, and then a Folium Map is created.
Here is my code.
#### login to DB
#### df = pd.read_sql("SELECT ... FROM ...)
m = folium.Map(location=[40.6976701, -74.2598704], zoom_start=10)
locations = list(zip(df.Latitude, df.Longitude))
#print(locations)
cluster = MarkerCluster(locations=locations)
m.add_child(cluster)
m
That produces this awesome map.
I can zoom in or zoom out, and the clusters expand or combine dynamically. Clearly the numbers are counts of items per cluster. I am wondering if I can add in another data point, like summing expenses per counts of items. So, in the image here, we can see a 3 at the top center. If that consists of 3 seperate expenses of 200 each, can I show the 600 as some kind of annotation, or label, pointing to the cluster? In the documentation I saw a parameters called popup and tooltip, but it doesn't seem to work for me.
Maybe I need to do some kind of aggregation, like this.
df.groupby(['Latitude','Longitude']).sum()
Just thinking out loud here.
I ended up doing this.
m = folium.Map(location=[40.6976701, -74.2598704], zoom_start=10)
for lat,lon,name,tip in zip(df.Latitude, df.Longitude, df.SiteName, df.Site):
folium.Marker(location=[lat,lon], tooltip = tip, popup = name)
m.add_child(cluster)
m
This lets you add a tooltip and a popup. That's pretty helpful. I still can't find a way to do sums. It seems like the only option is counts.
Hi There
I want to increase the accuracy of the marker detection from aruco.detectMarkers. So, I want to use Corner Refine Method with CORNER_REFINE_SUBPIX, but I do not understand how it is implemented in python.
Sample code:
frame = cv.imread("test.png")
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
para = aruco.DetectorParameters_create()
det_corners, ids, rejected = aruco.detectMarkers(gray,dictionary,parameters=para)
aruco.drawDetectedMarkers(frame,det_corners,ids)
Things I have tried:
para.cornerRefinementMethod()
para.cornerRefinementMethod(aruco.CORNER_REFINE_SUBPIX)
para.cornerRefinementMethod.CORNER_REFINE_SUBPIX
para = aruco.DetectorParameters_create(aruco.CORNER_REFINE_SUBPIX)
para = aruco.DetectorParameters_create(para.cornerRefinementMethod(aruco.CORNER_REFINE_SUBPIX))
They did not work, I’m pretty new to python ArUco so I hope that there is a simple and obvious solution.
I would also Like to implement enclosed markers like in the Documentation(Page 4). Do you happen to know if there is a way to generate these enclosed markers in python?
Concerning the first part of your question, you were pretty close: I assume your trouble is in switching and tweaking the "para" options. If so, you only need to set the corresponding values in the parameters object like
para.cornerRefinementMethod = aruco.CORNER_REFINE_SUBPIX
Note that "aruco.CORNER_REFINE_SUBPIX" is simply an integer. You can verify this by typing type(aruco.CORNER_REFINE_SUBPIX) in the console. Thus assigning values to the "para" object works like mentioned above.
You might also want to tweak the para.cornerRefinementWinSize which seems to be implemented in units of code pixels, not actual image pixel units.
Concerning the second part, you might have to write a function, that adds the boxes at the corner points, which you can get using the detectMarker function. Note that the corner points are always ordered clockwise, thus you can easily assign the correct offset values (like "up & left", "up & right" etc.).
para.cornerRefinementMethod = 1
may work.
I'm learning how to use Python and Basemap and would like to create a loop that produces a map of each projection type.
The projection types are: cea, mbtfpq, aeqd, sinu, poly, etc. So I just want a loop that does Basemap(width=x, height=y, projection=[projection type], ...) but can't figure out how to return the actual types of possible projections.
So far I've tried things like
proj = Basemap()
print(dir(proj))
and
proj = Basemap().projection
print(dir(proj))
but neither returns the types of projections it could be. I tried
for value in Basemap().projection:
print (value)
But it just returned
c
y
l
and that's it.
Closest I've gotten is
for value in Basemap().__dict__.items():
print (value)
but that returns a lot of info, seemingly the default values, but one of them is cyl, which is the default projection. I'm getting close but can't see how to iterate through each projection.
(My semantics are incorrect, so please correct me if I'm wrong!)
Edit: I'd like to learn how to do this without "cheating", i.e. since I know the types of projections possible, load those into an array and loop through the array. I'm trying to learn how to do it if I didn't know the possible values.
There's no need to cheat; looking at the source, you have a supported_projections list that contains all supported projections. You can just use that.
I have an array, of unknown length, of key:val pairs. Each pair occupies a row in a FlexGridSizer. The keys are in the first column, as wx.StaticTexts, and the vals are in the second column, as wx.TextCtrls.
The problem is that there isn't a lot of room available, and some of the vals are relatively long, and don't fit in the wx.TextCtrls. I would like to have all of the wx.TextCtrls be maybe 2 or 3 lines in height.
I've tried using style = wx.TE_MULTILINE, but that just adds a vertical scrollbar, as opposed to the default behaviour of scrolling horizontally with left/right/home/end etc.
Any ideas?
I suggest you use wxGrid.
http://docs.wxwidgets.org/2.9.2/overview_grid.html
According to the documentation for the wx.TextCtrl, you can apply the wx.HSCROLL style to it to make the control have a horizontal scrollbar, but this won't work on GTK1-based systems: http://xoomer.virgilio.it/infinity77/wxPython/Widgets/wx.TextCtrl.html
There's also an ExpandoTextCtrl that you might want to look at: from wx.lib.expando import ExpandoTextCtrl (see the wxPython demo for an example)
I ended up using FlexGridSizer. I made each of the val cells span across two rows, and added empty wx.Size()s below each key. The result is something like this: