Skip to content

How to create a pore distribution manually #2112

Answered by jgostick
livashu asked this question in Q&A
Discussion options

You must be logged in to vote

So you're saying that you have some like a histogram, and you want to add pores in proportion to height of each bar in your histogram. We do not have a function for this explicitly, but it should be do-able:

import numpy as np
import matplotlib.pyplot as plt
N = 1000  # N is the total number of pores diameter you want to generate
bin_centers = [0.5, 2.1, 3.3, 4.0, 5.0]  # In what ever units you like
bin_height = [0.05, 0.2, 0.4, 0.3, 0.15]  # Normalized to sum to 1.0
r = np.zeros(N)  
i = 0
while i < N:
    bin = np.random.randint(len(bin_centers))
    if np.random.rand() < bin_height[bin]:
        r[i] = bin_centers[bin]
        i += 1
plt.hist(r)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@livashu
Comment options

@mourendong
Comment options

@jgostick
Comment options

Answer selected by ma-sadeghi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants