How to arrange text annotations in julia makie in one row at the top? - text

I want to put text annotations along a line on the top. If I write same numbers (no matter which) in y array text will be aligned across center.
let
f = Figure()
ch = ["Ch2", "Ch3", "Ch17", "Ch18", "Ch19"]
x = Array(0:100:400)
y = [100, 100, 100, 100, 100]
ax = Axis(f[1, 1])
text!(x, y, text = ch, align = (:center, :center),
offset = (0, 0),
color = :black)
f
end
but if I change one item in y array
y = [10, 100, 100, 100, 100]
this happens:
How could I put "Ch2" to the same position on the top with other annotations?

Use ylims!(ax,0,110); to configure your axis.
let
f = Figure(;ylim=[0,110])
ch = ["Ch2", "Ch3", "Ch17", "Ch18", "Ch19"]
x = Array(0:100:400)
y = [100, 100, 100, 100, 100]
ax = Axis(f[1, 1]);
text!(x, y, text = ch, align = (:center, :center),
offset = (0, 0),color = :black)
ylims!(ax,0,110)
f
end

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 use a variable in a function from an earlier list in nested list comprehension

import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd="D:\\Tesseract\\tesseract.exe"
i = cv2.imread('1.png')
himg,wimg,_ = i.shape
[cv2.putText(i, b[0], (x, himg - y + 25), cv2.FONT_HERSHEY_SIMPLEX, 1, (50, 50, 255), 2) for x,y,w,h in [[int(x) for x in n ]for n in [[a[1],a[2],a[3],a[4]] for a in [b.split(' ') for b in pytesseract.image_to_boxes(i).splitlines()]]]]
cv2.imshow('',i)
cv2.waitKey(0)
in the line [cv2.putText(i, b[0], (x, himg - y + 25), cv2.FONT_HERSHEY_SIMPLEX, 1, (50, 50, 255), 2) for x,y,w,h in [[int(x) for x in n ]for n in [[a[1],a[2],a[3],a[4]] for a in [b.split(' ') for b in pytesseract.image_to_boxes(i).splitlines()]]]] , I get an error mainly because I am trying to use the the variable 'b' in my final function from an earlier list in the list comprehension.
I know this because [cv2.rectangle(i, (x,himg- y), (w,himg -h), (265,0,0), 2) for x,y,w,h in [[int(x) for x in n ]for n in [[a[1],a[2],a[3],a[4]] for a in [b.split(' ') for b in pytesseract.image_to_boxes(i).splitlines()]]]]
Works perfectly fine. Pls tell a way to achieve the desired result while maintaining the list comprehension.
I believe this alternate approach does what you seek to do:
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd="D:\\Tesseract\\tesseract.exe"
font = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
color = (50, 50, 255)
thickness = 2
image = cv2.imread('1.png')
image_height, image_width = image.shape
for row in pytesseract.image_to_boxes(image).splitlines():
cells = row.split(' ')
text = cells[0]
x, y, w, h = map(int, cells[1:5])
origin = (x, image_height - y + 25)
cv2.putText(image, text, origin, font, fontScale, color, thickness)
cv2.imshow('',image)
cv2.waitKey(0)

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 sign points on graphics in pyqtgraph?

I need your help in pyqtgraph library.
This is what I need:
It is my code. I plot pg.ScatterPlotItem.
w1 = view.addPlot()
w1.setXRange(0, 10)
w1.setYRange(6, 7)
s1 = pg.ScatterPlotItem(size=3, pen=pg.mkPen(None), brush=pg.mkBrush(255, 255, 255, 255))
dur1 = np.arange(0.1, 5, 2)
data = np.arange(0.1, 5, 2)
s1.setData(x= dur1, y = data) # text = ['A1','A2','A3']
w1.addItem(s1 )

Builiding a selection from a Dataframe

i want to build a selection from a dataframe based on double search-arguments. In detail:
I have build a search within a given Dataframe based on one value. This value can be given multiple times. The difference can be found in the row of the value. Here is a example:
TECHNIKART FSZ BEZEICHNUNG FIRMA PRODUKT_SPANNUNG KLIMA EW_KW MENGE_KW LEISTUNG_KW Ü
I get this Dataframe from following search in a bigger Dataframe:
key = '71E'
try:
geraet_dat2 = geraet_dat[geraet_dat.FSZ == key]
lang = len(geraet_dat2.index)
print(geraet_dat2)
My idea is now to have a if-else-query based on the length of the Dataframe. If the Dataframe has the lenght 1 i will print the values of the needed cells. If the Dataframe is longer than 1 the following popup appears:
def abfrage_selektion():
popup_selektion = Tk()
frame_selek = Frame(popup_selektion)
frame_selek.pack()
popup_selektion.configure(bg="Snow2")
popup_selektion.geometry('300x250')
popup_selektion.title('Bitte Gerät auswählen!')
LABEL_SELEKTION = LabelFrame(popup_selektion, text="Bitte Gerät auswählen: ")
LABEL_SELEKTION.place(x = 2, y = 2, width = 296, height = 246)
INFO = ttk.Label(LABEL_SELEKTION, justify=CENTER, text="Diese FSZ ist mehrfach verfügbar! \nBitte das entsprechende Gerät wählen!")
INFO.place(x = 50, y = 5)
SEPTR_1 = ttk.Separator(LABEL_SELEKTION, orient=HORIZONTAL)
SEPTR_1.place(x = 5, y = 40, width = 280)
GERAET = ttk.LabelFrame(LABEL_SELEKTION, text="Geräte: ")
GERAET.place(x = 15, y = 50, width = 260, height = 120)
LISTE = Listbox(GERAET, yscrollcommand=True)
LISTE.insert(1, '1')
LISTE.insert(2, '2')
LISTE.insert(3, '3')
LISTE.insert(4, '4')
LISTE.place(x = 5, y = 2, width = 240, height = 90)
SEPTR_2 = ttk.Separator(LABEL_SELEKTION, orient=HORIZONTAL)
SEPTR_2.place(x = 5, y = 180, width = 280)
BUTTON_OK = ttk.Button(LABEL_SELEKTION, text="OK")
BUTTON_OK.place(x = 5, y = 190, width = 280, height = 30)
that far everything is nice an clear for me.
But now the point i dont know how to solve:
In the popup i want a selection from the given Dataframe with more than one Dataset to select the wanted Data. The criteria for the selection should be 'BEZEICHNUNG' and 'PRODUKT_SPANNUNG'.
Do you have any ideas how i can do this? I searched in the web but didnt find a good solution for that.
Thank you for you help!

Resources