How to adjust scale to occupy more data in d3js - d3.js

I'm drawing a scatter plot with d3js. Using a simple linear scale with 1,2,3,4,5. This creates equal space like:
1 2 3 4 5
problem is, I have more data points between 2 and 3, 3 and 4. less data points between 1 and 2, 4 and 5. Is it possible to configure the scale to look like:
1 2 3 4 5
or instead of linear scale I should try some other scales? Please suggest.

First, a word of warning: distorting a scale (depending on the data you want to visualize) can maybe have "undesired" effects.
If you want to go ahead, I quickly set up a fiddle to show a possible way:
Fiddle
Basically, I am using custom domain/ranges to get the desired effect:
var x2 = d3.scale.linear()
.domain([1, 2, 3, 4, 5])
.range([0, 20, 80, 170, 200]);
Does that help?

Related

Changing the color map of vertexColor

I have a mesh, with gradient color using this type of code :
It's nice and beautiful, but I want to reduce the precision of the gradient and make it less smooth.
Here's an exemple
I've got data on a JSON, wich gave me coordinate for vertices 0, 2, 4 and 6. I calculate the other one after that. I've got a value on vertice 0, 2, 4 and 6, which I use to get the color value of that point, in HSL (like 0 is 0 in HSL and 1 is 240 in HSL)
With than given value, 1, 3, 5 and 7 have a color value depending of the vertice on the same line, and 8 got value from a pondered calculus.
If 0, 6 have a value of 0.5(green), and 2, 4 have a value of 1(red), then 7 is green, 3 is red, and 1, 8, 5 have a value of 0.75 (yellow).
With my material and colorVertex, the pixels between those point are calculated and can take a infity of value between 1 and 0.5.
Now, I want to now if it's possible to limit this infinity of values to fixed one, so it will look like that
I can't subdivise my mesh because the final one is really big and can't spend much more on calculus time. Is there a way to change the interpolation used by three.js so the pixel between my vertices have the colormap/color range that I want?
Thanks in advance

How do I manipulate the axis of a svg chart?

I am drawing a scatter chart using d3.js and epoch. The values that becomes the circles in the chart are based on log values, which makes my both axis go below zero.
var chart = $('#scatterchart').epoch({ type: 'scatter', data: scatterData, axes: ['bottom', 'left'], ticks: { right: 4, bottom: 4}, domain: [-1.4, 2], range: [-2,4], margins: { top: 10, right: 80, bottom: 60, left: 80 }, });
I would like to keep the position of the circles but manipulate the axis so that:
x(horisontal):
-1 -> 0.5
0 -> 1
1 -> 2
2 -> 4
y(vertical):
-2 -> 0.25
-1 -> 0.5
0 -> 1
1 -> 2
2 -> 4
3 -> 8
4 -> 16
Anyone that has any suggestion on how to do this?
I have no experience with epoch.js, and I don't know if you can tweak the axes it creates.
But you could try to transform your data before feeding it to your scatterplot generator.
If scatterData is an array, you could use array.map():
newData = scatterData.map(function(d){return someTransformFuntion(d);});
And adapt the input domain of your axis (actually, your scale) accordingly.
I have no experience with epoch.
But assuming it works on top of d3js, all you need to do is change the domain of both of your scales.
When you visualise your data, you work with a domain (for data) and a range (pixels on your screen). So to support negative values, you would need to adjust the domain to support [-2, 4] (for the y axis example).
As a bonus some reading about domains and negative values

Three.js Extending geometry

I would like to know how I can extend a geometry to a length.
Like a pipe in 2d that I will give a length/height.
See image
Wood
You can do that with scaling:
mesh.scale.set( 3, 4, 5 ). The number is the factor which you use to calculate the new size from the old. With mesh.scale.set( 3, 4, 5 )the mesh gets 3 times bigger on the x-axis, 4 times bigger on the y-axis und 5 times bigger on the z-axis.

d3 how to bind data to arc?

I'm new to d3 and would like some guidance in mapping a series of arcs or pie charts to my data. I have a CSV dataset and for each line from the CSV i want to create an arc or a pie chart using the CSV data to determine the radius size etc.
For example if i have a dataset containing:
arcName, startAngle, endAngle, r
arc1, 0, 5, 2
arc2, 1, 2, 5
I want this to produce 2 arcs, one with a radius of 2 and another with a radius of 5 since there are 2 object lines in my CSV file. Is there a way that I can create 2 arcs by mapping my data to the CSV file? Thanks.

Marking a specific point on a graph in MATLAB

I guess this is a very basic question.
I have a graph which I created in MATLAB. This is a graph of Power (y-axis) versus Frequency (x-axis).
The range of my x-axis is from 0 to 1000. Now here is my problem. I want to draw a line from specific points on the x-axis to the graph. For example, for points 40, 400, 950.
By using set(gca, 'XTick', [40 400 950]); I am able to mark these particular points. But I want to make it more visible by drawing straight vertical lines from these points.
Any help will be greatly appreciated. Thank you.
Use plot with endpoints with the same x value and different y values. (and don't forget to use myaa to beautify the output).
x = 0:0.1:2*pi;
y = sin(x);
plot(x,y);
hold on;
plot([0.6 0.6], [-1 1], 'Color', [0.7 0.7 0.7], 'LineWidth', 2);
plot([3.6 3.6], [-1 1], 'Color', [0.7 0.7 0.7], 'LineWidth', 2);
If you do this often I would recommend you a great submission from the FileExchange:
hline and vline
Just do:
vline([40 400 950])
Read the function documentation, if you want the line to have different properties than default.
I typically do this using something like this (is powers is a row vector).
powers = randn(1,1000)+40;
plot([1;1]*[40 400 950], [[0 0 0]; [powers([40 400 950])]],'k-')

Resources