Closed NimaDolatabadi closed 1 year ago
In your second example you plotting pdf of vector set with just single vector. If you want to plot pdf of individual clusters you should select all data belonging to that cluster. Something like:
for i in range(clust):
sel = df[kmeans.labels_ == i]
vectors2 = [vec2((sind(x - 90) * cosd(y)), (cosd(x + 90) * cosd(y))) for x, y in zip(sel['DipD'], sel['Dip'])]
vs2 = vec2set(vectors2)
p.bar(vs2, fc='White', ec=colors[i], ls="-", lw=1, label=f'Cluster {i+1}')
Anyway,for each group the values of densities will be different as is first example as number of samples is different. Only possibility would be to implement some weighting factor, which allows user to weight individual pdfs...
I can try to do it....
Using latest master version, you can use weight
kwarg...
from apsg import *
from apsg.helpers import sind, cosd
from sklearn.cluster import KMeans
##### ROSE DIAGRAM ######
# read data from CSV file
df = pd.read_csv('../test-stereonet-anticline1.csv')
# Add k-means clustering
clust = 5
kmeans = KMeans(n_clusters=clust, n_init="auto", random_state=0)
kmeans.fit(df)
centers = kmeans.cluster_centers_
SD = [(centers[i][0], centers[i][1]) for i in range(clust)]
colors = ['red', 'green', 'blue', 'orange', 'purple']
p = RosePlot(title='Test Rose Diagram', pdf_res=1000, tight_layout=True)
for i in range(clust):
sel = df[kmeans.labels_ == i]
vectors2 = [vec2((sind(x - 90) * cosd(y)), (cosd(x + 90) * cosd(y))) for x, y in zip(sel['DipD'], sel['Dip'])]
vs2 = vec2set(vectors2, name=f'Cluster {i+1}')
p.pdf(vs2, fc='White', ec=colors[i], lw=1, legend=True, weight=len(vs2)/len(df))
p.show()
Hello again. I was begining to getting no answer. it is a great pleasure of your help within the Plot. It really helped a lot. Regards
I have another question about this issue,
i believe that rose diagram reads the data as vector2, I just created this method to get it in 2d vector: vectors2 = [vec2((sind(x - 90) * cosd(y)), (cosd(x + 90) * cosd(y))) for x, y in zip(sel['DipD'], sel['Dip'])]
I think it is wrong because I am plotting rose diagram only for dip directions there is dip usage in this code. do you have any better idea on this one?
Regards
If you want to create unit length Vector2 you can use just a single argument, e.g.: v = vec2(30)
.
Or, you can create Vector2Set directly from the array as: vs = vec2set.from_direction(array)
So in your code it will be
for i in range(clust):
sel = df[kmeans.labels_ == i]
vs2 = vec2set.from_direction(sel['DipD'], name=f'Cluster {i+1}')
p.pdf(vs2, fc='White', ec=colors[i], lw=1, legend=True, weight=len(vs2)/len(df))
this is my code that plots normal Rose Diagram using PDF method:
the output is like the first photo that is drawn in Blue
and a second code that does plot each shape individually using this code:
and the output is the second photo that has different colors:
Here is the Issuse
I want those shapes completely separated so that i can set each one a new color meanwhile i want them to be scaled just like the first one.
and Idea on how to integrate this?
My input data is some folded beddings in righ hand rule format (ignore the header please) and it's it attached as well.
test-stereonet-anticline1.csv
Regards Nima