-
-
Save aletelecom/85e1a5060195dab39578703a6b5ca320 to your computer and use it in GitHub Desktop.
Viz 4 visualization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def double_hist_and_scatter_plot(df): | |
# Auxilliary parameters for the plot, number of bins | |
w = 2 | |
n = math.ceil((df['optical_power'].max() - df['optical_power'].min()) / w) | |
# definitions for the axes limits and positions | |
left, width = 0.1, 0.65 | |
bottom, height = 0.1, 0.65 | |
spacing = 0.005 | |
rect_scatter = [left, bottom, width, height] | |
rect_histx = [left, bottom + height + spacing, width, 0.2] | |
rect_histy = [left + width + spacing, bottom, 0.2, height] | |
# Ranges for the optical receiving power. This will allow us to separate the "good" samples | |
# from "critical" ones. | |
normal_range = [0.0, -21.9] | |
critical_range = [-22.0, -40] | |
# Colors for the ranges, green for the "good" ones, and red for the "bad" ones | |
normal_color = 'green' | |
critical_color = 'red' | |
# Lists of the ranges, to be able to iterate through them | |
ranges = [normal_range, critical_range] | |
colors = [normal_color, critical_color] | |
# X axis values, in this case are the distances | |
exes = [] | |
for range in ranges: | |
x = df[(df['optical_power'] <= range[0]) & (df['optical_power'] >= range[1])]['distance'] | |
exes.append(x) | |
# Y axis values for the plot, in this case are the Rx optical powers | |
yses = [] | |
for range in ranges: | |
y = df[(df['optical_power'] <= range[0]) & (df['optical_power'] >= range[1])]['optical_power'] | |
yses.append(y) | |
# start with a rectangular Figure | |
plt.figure(figsize=(30, 10)) | |
# Creation of the axes, and some parameters for the plot | |
ax_scatter = plt.axes(rect_scatter) | |
ax_scatter.tick_params(direction='in', top=True, right=True, labelsize=20) | |
ax_histx = plt.axes(rect_histx) | |
ax_histx.tick_params(direction='in', labelbottom=False, labelsize=20) | |
ax_histy = plt.axes(rect_histy) | |
ax_histy.tick_params(direction='in', labelleft=False, labelsize=20, labelrotation=45) | |
# the scatter plot: | |
for (x, y, color) in zip(exes, yses, colors): | |
ax_scatter.scatter(x, y, alpha=0.5, color= color) | |
ax_scatter.set_xlabel('Distance (m)', fontsize=30) | |
ax_scatter.set_ylabel('RX optical power (dBm)', fontsize=30) | |
# Plot the threshold line | |
ax_scatter.axhline(critical_range[0], color='red', lw=6) | |
# The histogram plots, only for the power we will use color ranges, for the distance no | |
for (x, y, color) in zip(exes, yses, colors): | |
ax_histy.hist(y, bins=n, orientation='horizontal', color=color) | |
ax_histx.hist(x, bins=n, color='green') | |
plt.show() | |
# CREACION E IMPRESION DE LA TABLA DE VALORES | |
bins = ['Optimal', 'Critical'] | |
data = [] | |
for y in yses: | |
data.append(y.count()) | |
table = pd.DataFrame(list(zip(bins, data)), columns=['Ranges', 'Quantity']) | |
print(table.head(5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment