« first day (2063 days earlier)      last day (1169 days later) » 

7:59 AM
anybody available for a quick matplotlib question?
 
8:18 AM
sure, but I'm not sure I can answer:)
 
8:36 AM
I have a Nx2 matrix, and I'm trying to do a scatter plot with 6 groups, where points 0:118 have one color, 118:267 have another color, etc. The colors I want to use are viridis of length 6. I would like to also have a separate legend entry for each group, so I'm doing this in a loop (is this avoidable?). My issue is with specifying the color of each group... I have viridis = cm.get_cmap('viridis', n_groups) but when I call ax.scatter I cannot say scatter(xdata,ydata, c=viridis[i])
 
I think you could make a vector that stores the group-index for each point, and use that to evaluate the colormap, and then pass that to scatter
 
so something like repelem?
I think I figured it out
 
haven't finished it yet, but this evaluates the current colormap in two colors:
import matplotlib.pyplot as plt
import numpy as np

n = 100
xy = np.random.rand(n,2)
g = np.linspace(0, 2-1e-5, n)
g = g.astype(np.int)
plt.scatter(xy[:, 0], xy[:, 1], c=g)
plt.show()
(the two distinct values in g)
@Dev-iL I think something like this?
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np

n = 100
xy = np.random.rand(n,2)
g = np.linspace(0, 6-1e-5, n)
xy[:, 0] += g #make nicely separated groups
g = g.astype(np.int)
viridis = cm.get_cmap('viridis', 6)
plt.scatter(xy[:, 0], xy[:, 1], c=viridis(g))
plt.show()
I think the key is having this group index
to assign the same color to each point of the group
 
8:51 AM
I used c=viridis.colors[i]
seems more straightforward
but wait... if you do it with a single scatter, how will you get separate legend entries?
 
ah haven't thought about this yet:)
 
That's what I did:
    viridis = cm.get_cmap('viridis', n_spk)
    fig, ax = plt.subplots(nrows=1, ncols=1)
    for i in range(0, n_spk):
        ax.scatter(*emb[clr_idx[i]:clr_idx[i+1], :].T, c=viridis.colors[i], label=labels[i])
 
oh check this out, they have a really nice solution that might be a lot simpler: stackoverflow.com/a/17412294/2913106
requires a loop though:)
 
The bottom line is you do end up calling scatter several times
 
@flawr @LuisMendo in bilbao we also do these: en.wikipedia.org/wiki/Carolina_(pastry)
very nice
 
9:07 AM
@Dev-iL I don't think you can avoid that unless you build the legend manually
 
@AnderBiguri this looks amazing
 
it tastes as it looks :D
 
wow, fancy
 
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np

n = 100
xy = np.random.rand(n,2)
g = np.linspace(0, 6-1e-5, n)
xy[:, 0] += g #make nicely separated groups
g = g.astype(np.int)
labels = np.array(['a','b','c','d','e','f'])
viridis = cm.get_cmap('viridis', 6)
s = plt.scatter(xy[:, 0], xy[:, 1], c=g, cmap=viridis)
plt.legend(s.legend_elements()[0], labels)
plt.show()
^ this should work
 
@AnderBiguri i.e. it tastes like diabetes?
 
9:08 AM
yessss
 
@AnderBiguri D:
 
@flawr might be more trouble than it's worth (in terms of readability and maintainability)
 
@AndrasDeak well I'd go with multiple scatter calls for less trouble:)
 
no comments on my implementation? :'(
 
sorry, I just popped in, teaching in 6 minutes :P
 
9:10 AM
@Dev-iL I thought you wanted to avoid multiple scatter calls?
 
I even replied! :P
 
@AndrasDeak quantum magnetovoodoo?
 
@Dev-iL nah; intro statistical physics
 
@AndrasDeak the docs actually suggest this method: matplotlib.org/stable/gallery/lines_bars_and_markers/…
 
label=... inside the scatter is definitely cleaner
that's also what I'd do in MATLAB (with '-DisplayName')
 
9:50 AM
Is there a way to return the index of the minimum/maximum alongside the value (like the 2nd output in MATLAB)?
 
argmax is the way to do it I think
 
Yeah I saw that this gives the index.. but then you need another call to max or min to get the values...?
 
you use the index
 
10:06 AM
I like the MATLAB way better...
 
same
 
10:38 AM
@AnderBiguri I want to try that!
 
Its funny because I never thought it was a Bilbao-only dessert, as its here everywhere
 
@AnderBiguri cognitive bias!
 
yup
Also people from Bilbao are know because they (we) think Bilbao is the center of the world
 
Culinary bias? Confectionery bias?
@Dev-iL I suspect the reason is the ufunc machinery. There's a general machinery underlying a lot of the efficient numpy functions, sharing APIs and implementation too. It would stick out (and maybe not possible) to have additional behaviour on top of the "give an array, get an array" basic behaviour.
 
they could overload np.amax to do ind=self.argmax(); return self[ind],ind; tho, no?
(not proper python but you get the idea)
 
10:48 AM
Yes, but why do that when it's slower and you can do it yourself?
it would only make sense to do the whole thing in C
so here's the implementation of max github.com/numpy/numpy/blob/…
ret = PyArray_GenericReduceFunction(arr, n_ops.maximum, axis,
                                    PyArray_DESCR(arr)->type_num, out);
it implements max as a reduction
 
makes sense, but a reduction could give you both. I get it, but as a high level language, I look for utility
otherwise I'd use C++
(Im exagerating, python is great)
 
Well, no, the point of numpy is also speed
there are plenty of design decisions that were made because the alternative would be slow
For instance sliding_window_view took so long to be implemented because it's only useful for prototyping. In real use cases it's likely to become a bottleneck.
 
but MATLAB is fast and does both, no?
 
@AnderBiguri don't know, but if it does it's because of JIT which python nor numpy doesn't natively have
well, numpy itself is compiled proper
 
yep yep
 
10:55 AM
@AndrasDeak huh that is nice to know! there is a similar function in pytorch, but it is almost as fast as e.g. the built in pooling functions
 
@flawr see the "notes" in the docs
 
 
8 hours later…
6:38 PM
@CrisLuengo DIP v3 huh? Congrats!
 
7:09 PM
@AnderBiguri If I ever go to Bilbao I will make sure to order one of those!
 
7:55 PM
@Dev-iL Thanks! I've been working on that since about 2014... Serious work started in 2016 or so, and it has tapered off a lot in the last two years. I figure if there's no more big changes coming, it's no longer beta.
Have been using it for serious work for a few years now. And other people I know too.
 
It looks like a really nice tool! Sadly, I didn't require anything like that in my work so far, but perhaps one day...
 
8:30 PM
@AnderBiguri You mean that they know Bilbao is the center of the universe.
 
I hope Bilbao is just a mutated form of the original name, Babel.
 
A bit like in "Book of Life", where they say this little town in the middle of Mexico is the center of the universe.
 
"Since we're the center of the universe we should build a tower to God"
God: "Oh no you don't!" BOOM, Basque
 
9:20 PM
@AndrasDeak well, Basque and Hungarian :)
 
@LuisMendo post plague
@CrisLuengo ovbiously, but I dont want to say it here, in public
@AndrasDeak lol
 
@AnderBiguri :-D So many things are getting backlogged...
 
9:51 PM
@flawr can't remember if you liked this kind of rock at all, but you should check this song out :D youtube.com/watch?v=tDFs6wwx1Yc hope you're doin well man
 
holy fuzz, that sound^^
I'm good, how are you?
 
haha yeah its got some great fuzz!
I'm doing well man :D not too much new on my end, living life almost entirely drama free
in lockdown for a year helps with that LOL
 
haha right?
and if there is drama you've only got yourself to blame:)
 
hahah yeah exactly
I have some drama with my cat.. he's getting a little fat
but that drama is being addressed with some diet change baha
 
the "shit in your shoes" school of drama
not what you normally see on jersey shore
 
10:03 PM
hahahah
 
@AndrasDeak Ah, I See You're a Man of Culture As Well
 
I don't actually watch trash tv :P
 
uncultured swine
2009 jersey shore is peak society
lol obviously sarcastic
@rayryeng Dude!! Not sure if I've had a chance to congratulate you on your second. He's getting big!! Barely recognize your oldest wow time is going by way too fast lol. Hope you're doing well
 

« first day (2063 days earlier)      last day (1169 days later) »