Color nodes in Networkx Graph based on specific values - networkx

I have looked a bit into the node_color keyword parameter of the nx.draw() method. Here are two different graphs colored using node_colors.
node_colors = [.5,.5,0.,1.]. Colors appear as expected
node_colors = [.9,1.,1.,1.]. Colors do not appear as expected
In the second image, I would expect the color of node 1 to be almost as dark. I assume what is happening is the colormap is getting scaled from the minimum value to the maximum value. For the first example, that's fine, but how can I set the colormap to be scaled from: 0=white, 1=blue every time?

You are correct about the cause of the problem. To fix it, you need to define vmin and vmax.
I believe
nx.draw(G, node_color=[0.9,1.,1.,1.], vmin=0, vmax=1)
will do what you're after (I would need to know what colormap you're using to be sure).
For edges, there are similar parameters: edge_vmin and edge_vmax.

Related

Vega-Lite - Error in the scales of circles and lines

I'm trying to use Vega-Lite to do a plot similar to a graph, where nodes are connected to other nodes by edges. The nodes vary in size according to a variable,while the edges width also vary.
The information for the nodes is stored in a different dataset than the information for the edges.
The problem is, once I try to plot everything together ("nodes" + "edges"), Vega-Lite is marking the size of the nodes very small (almost not visible). If I don't use the "size" for my edges plot, everything comes out normal.
Here is an example of what I'm doing (note that the notation is a bit different from native Vega-Lite, because I'm programming on Julia):
v1 = #vlplot(
mark={:circle,opacity=1},
x={μ[:,1],type="quantitative",axis=nothing},
y={μ[:,2],type="quantitative",axis=nothing},
width=600,
height=400,
size={μ_n,legend=nothing,type="q"})
v2 = #vlplot(
mark={"type"=:circle,color="red",opacity=1},
x={ν[:,1],type="quantitative",axis=nothing},
y={ν[:,2],type="quantitative",axis=nothing},
width=600,
height=400,
size={ν_m,legend=nothing,type="q"})
Then, when I create the visualization for the edges, and plot everything together:
v3 = #vlplot(
mark={"type"=:line,color="black",clip=false},
data = df,
encoding={
x={"edges_x:q",axis=nothing},
y={"edges_y:q",axis=nothing},
opacity={"ew:q",legend=nothing},
size={"ew:q",scale={range=[0,2]},legend=nothing},
detail={"pe:o"}},
width=600,
height=400
)
#vlplot(view={stroke=nothing})+v3+v2+v1
Any ideas on why this is happening and how to fix it?
(Note that the "scale" attribute is not the reason. Even if I remove it, the problem persists).
When rendering compound charts, Vega-Lite uses shared scales by default (see https://vega.github.io/vega-lite/docs/resolve.html): it looks like when your size scale is shared between the line and circle plots, it leads to poor results.
I'm not familiar with the VegaLite.jl syntax, but the JSON specification you'll want on the top-level chart is:
"resolve": {"scale": {"size": "independent"}}

Altair Scatter Chart

i am looking for a way to make a point chart based on multiple nominal conditions. i am plotting 2 values on x and y, but i would like to differentiate these points based on year as well as 'type'.
currently, the way i do it is to assign year to color while 'type' is assigned to shape
color=alt.condition(selection, alt.Color('Date:T'), alt.value('lightgray'), scheme='red' )
shape = alt.Shape('type:N')
a few questions:
is it possible to change the color scheme of the points instead of the default colors to say shades of red/blue/black, etc?
is it possible to assign one color scheme/shade (instead of shapes) to 'types'?
is it possible to change the color scheme of the points instead of the default colors to say shades of red/blue/black, etc?
Yes, see https://altair-viz.github.io/user_guide/customization.html#customizing-colors. You can use any of the built-in Vega color schemes, or define your own using the methods discussed there. From your example, it might look something like this:
color=alt.condition(
selection,
alt.Color('Date:T', scale=alt.Scale(scheme='reds')),
alt.value('lightgray')
)
is it possible to assign one color scheme/shade (instead of shapes) to 'types'?
No, there is no built-in way to apply two color scales based on two fields in the data (how would a mark choose between the two colors assigned to it?) One possible approach would be to use an opacity encoding for the second field, which is reflected in the lightness of the marks. For your example, it might look like this:
opacity='type:N'

Exchange phase of 2 image's fft and reconstruct [duplicate]

I'm using MATLAB for image processing and I came across a code with the instruction:
imshow(pixel_labels,[]);
when executed it give a binary image.
I have check the manual of the function on Mathworks.com, the most similar used mode is
imshow(I,[low,high]);
but they don't say a thing about the case where that array is empty ([])
I tried to remove it:
imshow(pixel_labels);
but all I see is a white board. I would like to know what is happening in the first use case (imshow(pixel_labels,[])), I hope from there I will understand why I get a white board in the last use case.
If I type help imshow in MATLAB, the first paragraph reads:
IMSHOW(I,[LOW HIGH]) displays the grayscale image I, specifying the
display
range for I in [LOW HIGH]. The value LOW (and any value less than LOW)
displays as black, the value HIGH (and any value greater than HIGH) displays
as white. Values in between are displayed as intermediate shades of gray,
using the default number of gray levels. If you use an empty matrix ([]) for
[LOW HIGH], IMSHOW uses [min(I(:)) max(I(:))]; that is, the minimum value in
I is displayed as black, and the maximum value is displayed as white.
so [] is simply shorthand for [min(pixel_labels(:)) max(pixel_labels(:))].

Sigmaplot: How to scale x-axis for correctly displaying boxplots

I want to display overlapping boxplots using Sigmaplot 12. When I choose the scale for the x-axis as linear then the boxes do indeed overlap but are much too thin. See figure below. Of course they should be much wider.
When I choose the scale of the x-axis to be "category", then the boxes have the right width, but are arranged along each single x-value.
I want the position as in figure 1 and the width as in figure 2. I tried to resize the box in figure 1 but when I choose 100% in "bar width" than it still looks like Figure 1.
many thanks!
okay, I found the answer myself. In Sigmaplot, there is often the need to prepare "style"-columns, for example if you want to color your barcharts, you need a column that holds the specific color names.
For my boxplot example I needed a column that has the values for "width". These had to be quite large (2000) in order to have an effect. Why ? I have no idea. First I thought it would be because of the latitude values and that the program interprets the point as "1.000"s, but when I changed to values without decimals, it didn´t get better.
Well, here is the result in color.
Have fun !

Pixel color matching estimate

For image scanning purposes, I'd like a pixel (which I can get from a UIImage) to match (for a certain percentage) to a pre-set color.
Say pink. When I scan the image for pixels that are pink, I want a function to return a percentage of how much the RGB value in the pixel looks like my pre-set RGB value. This way I'd like all (well, most) pink pixels to become 'visible' to me, not just exact matches.
Is anyone familiar with such an approach? How would you do something like this?
Thanks in advance.
UPDATE: thank you all for your answers so far. I accepted the answer from Damien Pollet because it helped me further and I came to the conclusion that calculating the vector difference between two RGB colors does it perfectly for me (at this moment). It might need some tweaking over time but for now I use the following (in objective c):
float difference = pow( pow((red1 - red2), 2) + pow((green1 - green2), 2) + pow((blue1 - blue2), 2), 0.5 );
If this difference is below 85, I accept the color as my target color. Since my algorithm needs no precision, I'm ok with this solution :)
UPDATE 2: on my search for more I found the following URL which might be quite (understatement) useful for you if you are looking for something similar.
http://www.sunsetlakesoftware.com/2010/10/22/gpu-accelerated-video-processing-mac-and-ios
I would say just compute the vector difference to your target color, and check that it's norm is less than some threshold. I suspect some color spaces are better than others at this, maybe HSL or L*ab, since they separate the brightness from the color hue itself, and so might represent a small perceptual difference by a smaller color vector...
Also, see this related question
Scientific answer: You should convert both colors to the LAB color space and calculate the euclidian distance there. That value is also called deltaE.
The LAB space was developed (using test persons) for exactly that reaason: so that different color pairs with equal distances in tnis space correspond to equal perceived color differences.
However, it sounds like you are not looking for matching a specific color, but rather a color range (lets say all skin tones). That might require more user input than just a reference color + a deltaE tollerance:
a reference color with 3 tollerances for hue, saturation and brightness
a cloud of refence color samples
...