0

I want the markersize in pyplot to correspond to a diameter in my experimental data.

Can I set the markersize, so it always shows a circle with a diameter of 6*10^-8 m? My x- and y-data is of the same scale.

font_size = 20

xmin = 0
xmax = np.sqrt(4) * 1e-6
ymin = 0
ymax = np.sqrt(4) * 1e-6

n_sim = 80
print("number of simulated dots:", n_sim)
density = n_sim / (xmax * ymax)
print("density:", density * 10 ** -12)
diameter = 60e-9
dots_sim = []

def no_nearby_dots(new_dot, dots_sim, min_distance):
    for dot in dots_sim:
        if np.sqrt((dot[0] - new_dot[0]) ** 2 + (dot[1] - new_dot[1]) ** 2) <= min_distance:
            return False
    return True

new_dot = True
dots_sim.append((np.random.uniform(xmin, xmax), np.random.uniform(ymin, ymax)))
failed_attempts = 0
while new_dot:
    xp = np.random.uniform(xmin, xmax)
    yp = np.random.uniform(ymin, ymax)
    if no_nearby_dots((xp, yp), dots_sim, diameter):
        dots_sim.append((xp, yp))
        failed_attempts = 0
    else:
        failed_attempts += 1
    if len(dots_sim) == n_sim:
        new_dot = False
    if failed_attempts > 1000:
        new_dot = False
        print("ERROR...exit loop")
        break

x_sim = [dot[0] for dot in dots_sim]
y_sim = [dot[1] for dot in dots_sim]


fig = plt.figure(1)
ax1 = fig.add_subplot()

plt.title('simulated pattern', fontsize=font_size)
plt.plot(x_sim, y_sim, 'b.', label='QDs', markersize=14)
plt.xlabel('x [$\mathrm{\mu m}$]', fontsize=font_size)
plt.xticks(fontsize=font_size)
plt.ylabel('y [$\mathrm{\mu m}$]', fontsize=font_size)
plt.yticks(fontsize=font_size)
plt.ticklabel_format(axis='both', style='Sci', scilimits=(-6, -6), useMathText=1)

ax1.xaxis.get_offset_text().set_visible(False)
ax1.yaxis.get_offset_text().set_visible(False)

plt.show()

This is the pattern:
enter image description here

  • 1
    In https://stackoverflow.com/a/44375267/4265407 proposed usage of `plt.Circle` instead `plt.plot` to draw points with diameter in plot units. – Stanislav Ivanov Sep 20 '20 at 10:44
  • I tried that, but the circles do not show: plt.Circle((x_sim[0], y_sim[0]), diameter/2, color='r', fill=False, label='circumference of the QD') –  Sep 20 '20 at 12:58
  • 1
    Do not miss `add_artist` call: `plt.gca().add_artist(plt.Circle(...))`. – Stanislav Ivanov Sep 20 '20 at 14:10
  • thank you, I solved it with your help. I didn't specify my x- and y-limits and used plt.Circle() now. –  Sep 20 '20 at 15:02

1 Answers1

0

SOLVED, ty Stanislav Ivanov. I didn't specify my limits on the x and y axis + I used plt.Circle() now instead of plt.plot().

fig = plt.figure(1)
ax1 = fig.add_subplot()
plt.title('simulated pattern', fontsize=font_size)
for i in range(n_sim):
    plt.gca().add_artist(plt.Circle((x_sim[i], y_sim[i]), diameter/2, color='r',
                                    fill=False, label='circumference of the QD'))
plt.xlabel('x [$\mathrm{\mu m}$]', fontsize=font_size)
plt.xticks(fontsize=font_size)
plt.ylabel('y [$\mathrm{\mu m}$]', fontsize=font_size)
plt.yticks(fontsize=font_size)
plt.xlim(xmin - 0.01*xmax, xmax + 0.01*xmax)
plt.ylim(ymin - 0.01*ymax, ymax + 0.01*ymax)
plt.ticklabel_format(axis='both', style='Sci', scilimits=(-6, -6), useMathText=1)
ax1.xaxis.get_offset_text().set_visible(False)
ax1.yaxis.get_offset_text().set_visible(False)

New Pattern