Graphviz Selfloops overlap labels - layout

I have a simple graphiz graph that I am trying to render with dot. It is a series of self-loops on a single state:
digraph FST {
size = "8.5,11";
label = "";
rankdir=LR;
bgcolor = "transparent";
center = 1;
rank = same;
margin = 0;
orientation = Portrait;
0 [label = "0", shape = doublecircle, style = bold, fontsize = 14, color="#339933"]
0 -> 0 [label = "a", fontsize = 14];
0 -> 0 [label = "b", fontsize = 14];
0 -> 0 [label = "cd", fontsize = 14];
0 -> 0 [label = "efg", fontsize = 14];
0 -> 0 [label = "a", fontsize = 14];
0 -> 0 [label = "q", fontsize = 14];
0 -> 0 [label = "xyzabc", fontsize = 14];
}
I compile this like:
$ cat self-loop.dot | dot -Tpng > self-loop.png
The edges however, overlap the labels and looks ridiculous. Is there some way to prevent the edges from doing this? To make them flare out more?
Resulting Graph
I have had no luck scouring forums or the graphviz documentation.

Multi-loops are a pain. Using ports (https://www.graphviz.org/doc/info/attrs.html#k:portPos) helps. Bur rankdir also causes problems, so I changed it.
digraph FST {
size = "8.5,11";
label = "";
//rankdir=LR; // note the change in rankdir!!
bgcolor = "transparent";
center = 1;
rank = same;
margin = 0;
orientation = Portrait;
0 [label = "0", shape = doublecircle, style = bold, fontsize = 14, color="#339933"]
0:nw -> 0:ne [label = "a", fontsize = 14];
0:nw -> 0:ne [label = "\nb", fontsize = 14];
0:nw -> 0:ne [label = "\ncd", fontsize = 14];
0:nw -> 0:ne [label = "\nefg ", fontsize = 14];
0:nw -> 0:ne [label = " a ", fontsize = 14];
0:nw -> 0:ne [label = " q ", fontsize = 14];
0:nw -> 0:ne [label = "xyzabc", fontsize = 14];
}
Giving:

Related

How to change color of mark on topoplot interactively?

I want to create interactive line- and topoplot depending on menu. I figured out how to make red the line chosen in menu, but it doesn't work for topoplot marks (black circles inside topoplot). I can change it manually (cmap[][4] = RGB{N0f8}(1.0,0.0,0.0)), but how to do that interactively?
f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98), resolution = (1500, 700))
ax = Axis(f[1:3, 1], xlabel = "Time [s]", ylabel = "Voltage amplitude [µV]")
N = 1:length(pos) #1:4
hidespines!(ax, :t, :r)
GLMakie.xlims!(-0.3, 1.2)
hlines!(0, color = :gray, linewidth = 1)
vlines!(0, color = :gray, linewidth = 1)
times = range(-0.3, length=size(dat_e,2), step=1 ./ 128)
lines = Dict()
for i in N
mean_trial = mean(dat_e[i,:,:],dims=2)[:,1]
line = lines!(times, mean_trial, color = "black")
lines[i] = line
end
hidedecorations!(ax, label = false, ticks = false, ticklabels = false)
topo_axis = Axis(f[2, 2], width = 178, height = 178, aspect = DataAspect())
Makie.xlims!(low = -0.2, high = 1.2)
Makie.ylims!(low = -0.2, high = 1.2)
topoMatrix = eegHeadMatrix(pos[N], (0.5, 0.5), 0.5)
cmap = Observable(collect(ColorScheme(range(colorant"black", colorant"black", length=30))))
#cmap[][4] = RGB{N0f8}(1.0,0.0,0.0)
topo = eeg_topoplot!(topo_axis, N, # averaging all trial of 30 participants on Xth msec
raw.ch_names[1:30];
positions=pos, # produced automatically from ch_names
interpolation=NullInterpolator(),
enlarge=1,
#colorrange = (0, 1), # add the 0 for the white-first color
colormap = cmap[],
label_text=false)
hidedecorations!(current_axis())
hidespines!(current_axis())
num_prev = 0
menu = Menu(f[3, 2], options = raw.ch_names[1:30], default = nothing)#, default = "second")
on(menu.selection) do selected
if selected != nothing
num = findall(x->x==menu.selection[], raw.ch_names[1:30])[]
if num_prev != 0
lines[num_prev].color = "black"
cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
end
lines[num].color = "red"
cmap[][num] = RGB{N0f8}(1.0,0.0,0.0)
num_prev = num
end
end
notify(menu.selection)
#print(cmap[])
f
We solved this by putting this string at the end of the menu.selection section:
notify(lines)
It works, because lines() automatically creates Observable.

How to get real Landsat image conrers

How I can get actual coordinates of Landsat image corners (see image to understand) ?
From metadata file (..._MTL.txt) I can get coordinates of red corners, but I need to get coordinates of green corners.
I work with GeoTIFF files using GDAL.
I need to get correct latitude and longitude of green points.
Can I do it using python3?
Thanks for help
Metadata file
GROUP = L1_METADATA_FILE
GROUP = METADATA_FILE_INFO
ORIGIN = "Image courtesy of the U.S. Geological Survey"
REQUEST_ID = "9991103150002_00325"
PRODUCT_CREATION_TIME = 2011-03-16T20:14:24Z
STATION_ID = "EDC"
LANDSAT5_XBAND = "1"
GROUND_STATION = "IKR"
LPS_PROCESSOR_NUMBER = 0
DATEHOUR_CONTACT_PERIOD = "1016604"
SUBINTERVAL_NUMBER = "01"
END_GROUP = METADATA_FILE_INFO
GROUP = PRODUCT_METADATA
PRODUCT_TYPE = "L1T"
ELEVATION_SOURCE = "GLS2000"
PROCESSING_SOFTWARE = "LPGS_11.3.0"
EPHEMERIS_TYPE = "DEFINITIVE"
SPACECRAFT_ID = "Landsat5"
SENSOR_ID = "TM"
SENSOR_MODE = "BUMPER"
ACQUISITION_DATE = 2010-06-15
SCENE_CENTER_SCAN_TIME = 04:57:44.2830500Z
WRS_PATH = 145
STARTING_ROW = 26
ENDING_ROW = 26
BAND_COMBINATION = "1234567"
PRODUCT_UL_CORNER_LAT = 49.8314223
PRODUCT_UL_CORNER_LON = 84.0018859
PRODUCT_UR_CORNER_LAT = 49.8694055
PRODUCT_UR_CORNER_LON = 87.4313889
PRODUCT_LL_CORNER_LAT = 47.8261840
PRODUCT_LL_CORNER_LON = 84.1192898
PRODUCT_LR_CORNER_LAT = 47.8615913
PRODUCT_LR_CORNER_LON = 87.4144676
PRODUCT_UL_CORNER_MAPX = 284400.000
PRODUCT_UL_CORNER_MAPY = 5524200.000
PRODUCT_UR_CORNER_MAPX = 531000.000
PRODUCT_UR_CORNER_MAPY = 5524200.000
PRODUCT_LL_CORNER_MAPX = 284400.000
PRODUCT_LL_CORNER_MAPY = 5301000.000
PRODUCT_LR_CORNER_MAPX = 531000.000
PRODUCT_LR_CORNER_MAPY = 5301000.000
PRODUCT_SAMPLES_REF = 8221
PRODUCT_LINES_REF = 7441
PRODUCT_SAMPLES_THM = 4111
PRODUCT_LINES_THM = 3721
BAND1_FILE_NAME = "L5145026_02620100615_B10.TIF"
BAND2_FILE_NAME = "L5145026_02620100615_B20.TIF"
BAND3_FILE_NAME = "L5145026_02620100615_B30.TIF"
BAND4_FILE_NAME = "L5145026_02620100615_B40.TIF"
BAND5_FILE_NAME = "L5145026_02620100615_B50.TIF"
BAND6_FILE_NAME = "L5145026_02620100615_B60.TIF"
BAND7_FILE_NAME = "L5145026_02620100615_B70.TIF"
GCP_FILE_NAME = "L5145026_02620100615_GCP.txt"
METADATA_L1_FILE_NAME = "L5145026_02620100615_MTL.txt"
CPF_FILE_NAME = "L5CPF20100401_20100630_09"
END_GROUP = PRODUCT_METADATA
GROUP = MIN_MAX_RADIANCE
LMAX_BAND1 = 193.000
LMIN_BAND1 = -1.520
LMAX_BAND2 = 365.000
LMIN_BAND2 = -2.840
LMAX_BAND3 = 264.000
LMIN_BAND3 = -1.170
LMAX_BAND4 = 221.000
LMIN_BAND4 = -1.510
LMAX_BAND5 = 30.200
LMIN_BAND5 = -0.370
LMAX_BAND6 = 15.303
LMIN_BAND6 = 1.238
LMAX_BAND7 = 16.500
LMIN_BAND7 = -0.150
END_GROUP = MIN_MAX_RADIANCE
GROUP = MIN_MAX_PIXEL_VALUE
QCALMAX_BAND1 = 255.0
QCALMIN_BAND1 = 1.0
QCALMAX_BAND2 = 255.0
QCALMIN_BAND2 = 1.0
QCALMAX_BAND3 = 255.0
QCALMIN_BAND3 = 1.0
QCALMAX_BAND4 = 255.0
QCALMIN_BAND4 = 1.0
QCALMAX_BAND5 = 255.0
QCALMIN_BAND5 = 1.0
QCALMAX_BAND6 = 255.0
QCALMIN_BAND6 = 1.0
QCALMAX_BAND7 = 255.0
QCALMIN_BAND7 = 1.0
END_GROUP = MIN_MAX_PIXEL_VALUE
GROUP = PRODUCT_PARAMETERS
CORRECTION_METHOD_GAIN_BAND1 = "CPF"
CORRECTION_METHOD_GAIN_BAND2 = "CPF"
CORRECTION_METHOD_GAIN_BAND3 = "CPF"
CORRECTION_METHOD_GAIN_BAND4 = "CPF"
CORRECTION_METHOD_GAIN_BAND5 = "CPF"
CORRECTION_METHOD_GAIN_BAND6 = "IC"
CORRECTION_METHOD_GAIN_BAND7 = "CPF"
CORRECTION_METHOD_BIAS = "IC"
SUN_AZIMUTH = 141.2669762
SUN_ELEVATION = 59.9909680
OUTPUT_FORMAT = "GEOTIFF"
END_GROUP = PRODUCT_PARAMETERS
GROUP = CORRECTIONS_APPLIED
STRIPING_BAND1 = "NONE"
STRIPING_BAND2 = "NONE"
STRIPING_BAND3 = "NONE"
STRIPING_BAND4 = "NONE"
STRIPING_BAND5 = "NONE"
STRIPING_BAND6 = "NONE"
STRIPING_BAND7 = "NONE"
BANDING = "N"
COHERENT_NOISE = "N"
MEMORY_EFFECT = "Y"
SCAN_CORRELATED_SHIFT = "Y"
INOPERABLE_DETECTORS = "N"
DROPPED_LINES = "N"
END_GROUP = CORRECTIONS_APPLIED
GROUP = PROJECTION_PARAMETERS
REFERENCE_DATUM = "WGS84"
REFERENCE_ELLIPSOID = "WGS84"
GRID_CELL_SIZE_THM = 60.000
GRID_CELL_SIZE_REF = 30.000
ORIENTATION = "NUP"
RESAMPLING_OPTION = "CC"
MAP_PROJECTION = "UTM"
END_GROUP = PROJECTION_PARAMETERS
GROUP = UTM_PARAMETERS
ZONE_NUMBER = 45
END_GROUP = UTM_PARAMETERS
END_GROUP = L1_METADATA_FILE
END
You might first find the contour with the biggest area. Then try some algorithm to find the points you want. It seems that the satellite picture in the image is not a perfect rectangle, so you can't fit a rectangle on it using OpenCV's built-in methods.
You should try something like that:
import cv2
import numpy as np
img = cv2.imread('z_edited.jpg')
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(imgray, (11, 11), 0)
ret, thresh = cv2.threshold(blurred, 27, 255, 0)
cnts, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
max_area = 0
max_area_index = 0
for i, cnt in enumerate(cnts):
area = cv2.contourArea(cnt)
if area > max_area:
max_area = area
max_area_index = i
x_min = np.min(cnts[max_area_index][:, 0, 0])
x_max = np.max(cnts[max_area_index][:, 0, 0])
y_min = np.min(cnts[max_area_index][:, 0, 1])
y_max = np.max(cnts[max_area_index][:, 0, 1])
(x_left, y_left) = (x_min, cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 0] == x_min)), 0, 1])
(x_right, y_right) = (x_max, cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 0] == x_max)), 0, 1])
(x_down, y_down) = (cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 1] == y_max)), 0, 0], y_max)
(x_top, y_top) = (cnts[max_area_index][np.max(np.where(cnts[max_area_index][:, 0, 1] == y_min)), 0, 0], y_min)
cv2.circle(img, (x_left, y_left), 10, (0, 0, 255), thickness=8)
cv2.circle(img, (x_right, y_right), 10, (0, 0, 255), thickness=8)
cv2.circle(img, (x_down, y_down), 10, (0, 0, 255), thickness=8)
cv2.circle(img, (x_top, y_top), 10, (0, 0, 255), thickness=8)
# cv2.drawContours(img, cnts, max_area_index, (0, 255, 0), 2)
cv2.namedWindow('s', cv2.WINDOW_NORMAL)
cv2.imshow('s', img)
cv2.waitKey(0)
And the result looks like:
Using this code you can find the coordinates of the corners of the satellite picture inside the image(red points).
Also need to say I have assumed that your satellite picture background is completely black(the image you have uploaded, has a thin gray strip around the whole image).

Tkinter Frame and griding

I am designing a front end using Tkinter but the .grid() option doesn't work as expected. I want to divide my screen to two section, LEFT and Right. All the buttons and labels on the left and the rest on the right.
# Initialise frames
self.frame_left = tk.Frame(root, bg = "pink", width = 100, height = 100).grid(row = 0, column = 0, sticky = 'E')
self.frame_right = tk.Frame(root, bg = "red", width = 100, height = 100).grid(row = 0, column = 1, sticky = 'W')
root.grid_columnconfigure(0, weight=0)
root.grid_columnconfigure(1, weight=0)
#labels
self.Name_Label = tk.Label(self.frame_left, text = "Name", font = 12, fg = 'green').grid(row = 1, column = 1)
self.Phone_Label = tk.Label(self.frame_left, text = "Phone Number", font = 12, fg= 'green').grid(row = 1, column =2)
self.University_label = tk.Label(self.frame_left, text = "University", font = 12, fg = 'green').grid(row = 1, column = 3)
#Search boxex
self.Name_box = tk.Entry(self.frame_left, width = 12, borderwidth = 2).grid(row = 2, column = 1)
self.Phone_box = tk.Entry(self.frame_left, width = 12, borderwidth = 2).grid(row = 2, column = 2)
self.Phone_box = tk.Entry(self.frame_left, width = 12, borderwidth = 2).grid(row = 2, column = 3)
# Buttons
self.Search_button = tk.Button(self.frame_left, text='Search', padx = 10, pady = 10, font = 12, fg = 'black').grid(row = 5, column = 1)
#Screen
#self.Screen = tk.Listbox(self.frame_right, width = 20, height = 20, font = 1).grid(row = 0, column = 0)
It seems the labels and buttons are being placed on the root window not the frames that has been defined.
Appreciate your help.
Regards
Khisrow
To divide your screen into 2 parts, you need to use the option columnconfigure:
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=1)
This creates a grid on the root window with 2 columns in which your self.frame_left and self.frame_right can be placed.
When you store a .grid() item you are not storing the widget:
self.frame_left = tk.Frame(root, bg = "pink", width = 100, height = 100).grid(row = 0, column = 0, sticky = 'E')
Stores the grid object to the variable, not the Frame.
This can be fixed by doing the creation and grid in two lines.
import tkinter as tk
class Test():
def __init__(self):
root = tk.Tk()
#EXAMPLE OF DIFFERENCE
self.frame_left = tk.Frame(root, bg = "pink", width = 100, height = 100).grid(row = 0, column = 0, sticky = 'E')
print(self.frame_left, "DIDN'T STORE THE FRAME")
self.frame_left = tk.Frame(root, bg = "pink", width = 100, height = 100)
self.frame_left.grid(row = 0, column = 0, sticky = 'E')
print(self.frame_left, "STORED THE FRAME")
#EXAMPLE OF DIFFERENCE
# Initialise frames
self.frame_left = tk.Frame(root, bg = "pink", width = 100, height = 100)
self.frame_left.grid(row = 0, column = 0, sticky = 'E')
self.frame_right = tk.Frame(root, bg = "red", width = 100, height = 100)
self.frame_right.grid(row = 0, column = 1, sticky = 'W')
root.grid_columnconfigure(0, weight=0)
root.grid_columnconfigure(1, weight=0)
#labels
self.Name_Label = tk.Label(self.frame_left, text = "Name", font = 12, fg = 'green').grid(row = 1, column = 1)
self.Phone_Label = tk.Label(self.frame_left, text = "Phone Number", font = 12, fg= 'green').grid(row = 1, column =2)
self.University_label = tk.Label(self.frame_left, text = "University", font = 12, fg = 'green').grid(row = 1, column = 3)
#Search boxex
self.Name_box = tk.Entry(self.frame_left, width = 12, borderwidth = 2)
self.Name_box.grid(row = 2, column = 1)
self.Phone_box = tk.Entry(self.frame_left, width = 12, borderwidth = 2)
self.Phone_box.grid(row = 2, column = 2)
self.Phone_box = tk.Entry(self.frame_left, width = 12, borderwidth = 2)
self.Phone_box.grid(row = 2, column = 3)
# Buttons
self.Search_button = tk.Button(self.frame_left, text='Search', padx = 10, pady = 10, font = 12, fg = 'black').grid(row = 5, column = 1)
#Screen
#self.Screen = tk.Listbox(self.frame_right, width = 20, height = 20, font = 1).grid(row = 0, column = 0)
Test()
EDIT: added a listbox with scrollbar
# Screen
scrollbar = tk.Scrollbar(self.frame_right)
scrollbar.grid(row = 0, column = 1, sticky = 'nsw')
self.Screen = tk.Listbox(self.frame_right, width = 20, height = 5, font = 1)
self.Screen.grid(row = 0, column = 0, sticky = 'e')
self.Screen.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=self.Screen.yview)

Seaborn boxplot whiskers are missing from just one category

I've been using the Seaborn library to plot box plots. In one instance, I see that the whiskers are randomly missing from one of my categorical variables.
fig, ax = plt.subplots(1, 1, figsize = (60,30))
plt.axhline(y = 0, color = 'k', linestyle = ':', linewidth = 2)
ax = sns.boxplot(x = 'Neighborhood', y = 'Price difference', data = sf_data_residuals_neighborhoods,
showfliers = False, order = list(neighborhood_order_residuals['Neighborhood']), linewidth = 5)
ax = sns.stripplot(x = 'Neighborhood', y = 'Price difference', data = sf_data_residuals_neighborhoods,
order = list(neighborhood_order_residuals['Neighborhood']), jitter = 0.25, size = 15,
linewidth = 3, edgecolor = 'black', alpha = 0.5)
# set axis properties
plt.xticks(rotation=45, fontname = 'Helvetica', fontsize = 42, ha = 'right')
plt.yticks(fontname = 'Helvetica', fontsize = 42)
plt.xlabel('San Francisco neighborhood', fontsize = 55, fontname = 'Arial', fontweight = 'bold')
plt.ylabel('Actual - predicted price ($M)', fontsize = 55, fontname = 'Arial',
fontweight = 'bold')
scale = 1000000; ax.set_ylim(-1000000, 3000000); ax.yaxis.labelpad = 25
ticks = ticker.FuncFormatter(lambda y, pos: '{0:g}'.format(y/scale))
ax.xaxis.set_tick_params(width = 3, length = 15)
ax.yaxis.set_tick_params(width = 3, length = 15)
ax.yaxis.set_major_formatter(ticks)
plt.setp(ax.spines.values(), linewidth = 3)
This produces the desired plot, but appears to leave out whiskers for the Potrero Hill category:
I've tried manually stipulating the default whis = 1.5 setting in sns.boxplot() but this does not make the missing whiskers appear.
Any idea what might be causing this?

How to avoid arrow heads reaching into boxes?

I create SVG output with dot. When I set penwidth = 2 for nodes and edges, the arrowheads point slightly inside the boxes. Is there a way to avoid this? Maybe by drawing the nodes after the edges? Or by reducing the length of the edges/arrows to 95%? I've tried to find an attribute that would allow this, but could not find something that worked.
NOTE: Effect can't be seen when converting to png or jpg. Create SVG with dot -Tsvg file.dot > file.svg and view in browser.
This is my dot file:
digraph configure {
node [
shape = box,
fontname = "Courier",
style = "filled",
fillcolor = "#cccccc",
penwidth = 2
];
A [label = "configure.in"];
B [label = "autoconf\nGNU m4", fillcolor = ".7 .3 1.0"];
C [label = "configure"];
X [label = "cfg.hin", fillcolor = "#eeeeee"];
Y [label = "cfg.h", fillcolor = "#eeeeee"];
edge [
fontname = "Palatino-Italic",
fontsize = 9,
penwidth = 2,
arrowsize = 1
];
A -> B [label = " is input to"];
B -> C [label = " creates"];
subgraph cfg {
rank = same;
rankdir = LR;
X -> C [label = "is input to "];
C -> Y [label = "creates "];
}
}

Resources