Set xaxis of imagesc with scaled binned values - image

I have a matrix(20x400) and I am plotting it with imagesc in MATLAB where y axis having 20 values and xaxis having 400 values.
However, I would like to know how can I scale this xaxis 400 to intervals like between 0:20 = 1, 20:40 = 2 until 380:400 = 20; and setting x axis of imagesc in 0-20 scale with the values of 0-20.
I hope it is clear what I am intended to do.

Related

Axes set-up with matlab imshow

I have two images (I1 and I2) that I want to plot through subplot as follows. For sake of simplicity I created two fake images with size 512x512 pixels.
I1 = randn(512);
I2 = randn(512);
% display
f1 = figure();
axis on;
subplot(1,2,1), imshow(uint8(I1));
subplot(1,2,2), imshow(uint8(I2));
I want the Y axis to show just the following ticks: 0 100 200 300 400 500. Therefore exactly as the X axis, so that it is clear that the image size is also bigger than 500 pixels. How can I do it? Thanks a lot!
You should move the axis on to the end of the script and specify the XTick and XTickLabel properties.
I1 = randn(512);
I2 = randn(512);
% display
f1 = figure();
s1=subplot(1,2,1);
imshow(uint8(I1));
set(s1,'XTick',0:100:500);
set(s1,'XTickLabel',0:100:500);
axis on;
s2=subplot(1,2,2);
imshow(uint8(I2));
set(s2,'XTick',0:100:500);
set(s2,'XTickLabel',0:100:500);
axis on;

DimpleJS. Y axis values in percentages

I am plotting Vertical Grouped Bar Chart from a csv file which contains Discount, Rating and Clicked. The data is csv is like 55,2,1 and 40,5,0 etc. Here the first value(55,40) are the discounts, (2,5) rating and 1 and 0 correspond to clicked and not clicked respectively. On plotting the chart with following code.
var svg2 = dimple.newSvg("#discountContainer", 590, 400);
d3.csv("/svm1000.csv", function (data) {
var myChart2 = new dimple.chart(svg2, data);
myChart2.setBounds(60, 30, 510, 330)
myChart2.addCategoryAxis("x", ["rating", "action"]);
var y = myChart2.addMeasureAxis("y", "discount");
//y.tickFormat = "%";
myChart2.addSeries("action", dimple.plot.bar);
myChart2.addLegend(65, 10, 510, 20, "right");
myChart2.draw();
});
The problem is I want to represent y axis in percentage in multiple of 10, like 0%, 10%, 20% .. 100%. Right now the y axis values are like 0,2k,4k,6k...20k. So how to represent y axis in percentage.
I see this question is old, so this answer may not help you, but for others facing similar requirements this might be helpful.
dimple.js provide method to have percentage series
myChart2.addPctAxis("y", "discount");
but remember you can't create both Value and Percentage in same axis, you might need to have dual axis graph
var x = myChart2.addCategoryAxis("x", ["rating", "action"]);
var y1 = myChart2.addPctAxis("y", "discount");
var y2 = myChart2.addMeasureAxis("y", "amount"); // the field with value ranges 1000...
also you don't able to use grouped bar chart; for axis 1 use bar chart and for axis 2 use line or vice versa like
myChart2.addSeries("action", dimple.plot.bar, [x, y1]);
myChart2.addSeries("action", dimple.plot.line, [x, y2]);

How to reduce Y-Axis scale values in d3 bar chart?

I use an bar chart. Count of y-axis is 9. So y-axis values are displaying from 0 to 9. It looks very congested. I need to reduce the values like displayed by multiplied by 2/3.
Here is my Y-axis code:
yAxis = d3.svg.axis()
.scale(yRange)
//.ticks(2)
// .tickValues(function(d,i){return totalEmpArray[i];})
.tickSize(0)
.orient("left")
.tickSubdivide(true);
yAxis.ticks(6)
or
yAxis.tickValues([0,2,4,6,8,10])
See documentation.

D3.js - Log scale starting at zero

I am plotting a y axis which should be defined in log scale. The range is from 0 to 1000.
If I try,
var yScale = d3.scale.log().domain([0, 1000]).range([height, 0]);
d3.svg.axis().scale(yScale).orient("left");
Then only 0.01 is shown in the y axis. According to the d3 documentation, log scale range cannot have zero.
I tried this https://stackoverflow.com/a/13228478/690567, but using the scale in the axis throws error.
Is there any other way plot this range (0 to 1000) in y axis?

d3 unevenly distributed scaling

any suggestions for drawing axes with unequal spacing between the values. For instance I am currently drawing axes using:
yScale = d3.scale.linear().domain([0, 60000]).range([height, 0])
I need more spacing between 0 and 5000 than distributing all the data points equally
Try using a polylinear scale:
yScale = d3.scale.linear().domain([0, 5000, 60000]).range([height, height/2, 0])
The range (0, 5000) and (5000, 60000) will both be given the same amount of space.

Resources