D3.js - Log scale starting at zero - d3.js

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?

Related

Set xaxis of imagesc with scaled binned values

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.

line chart issue in dc.js when y value is 0

in dc.js line chart ,when all y value is zero corresponding to the x axis value line is not drawing. it just displying xaxis and y-axis without ticks.Is it possible to draw line on the x axis with corresponding y value as 0 with x-axis name(field name)?

Seaborn Stripplot Axis Values with Correct Scaling

I'm trying to plot some data in seaborn where the x values are percentages*100 as floating point numbers (ie 90.909). When I make the plot:
fig, ax = plt.subplots(figsize=(10,10))
ax = sns.stripplot(df_12['% ident'], df_12['length'], jitter=True)
The decimals in the floating points make the X axis unreadable:
Initial Plot
I would like to set the x axis to show only whole number multiples of 5 (ie 80, 85, 90, 95, 100).
One method I have tried is the following:
fmt = '{:0.0f}'
xticklabels = []
count = 0
for item in ax.get_xticklabels():
count+= 1
item.set_text(fmt.format(float(item.get_text())));
xticklabels += [item];
ax.set_xticklabels(xticklabels);
This succeeds in changing the axis values to integers, but the axis looks busy. The numbers shown are also inconsistent between similar datasets.
Second Plot
I would like to reduce the total number of values shown on the axis. I have tried to use
ax.xaxis.set_major_locator(plt.MaxNLocator(5))
Or similarly
ax.xaxis.set_major_locator(plt.MaxNLocator(5))
ax.set_xticklabels([80, 85, 90, 95, 100])
Which give outputs similar to this:
Third Plot
If you compare this to the previous plot, you'll notice the x axis labels no longer relate to the points plotted. How do I set the values of the x axis while still keeping them related to the points plotted?
Other things I have tried:
ax.set_xlim(75, 100)
This and any variants result in a blank plot.
ax.set(xticklabels=[75,80,85,90,95,100])
Does the same thing where the axis labels don't match the data.
ax.set(xticks=range(75,101), xticklabels=[75,80,85,90,95,100])
Results in all the data points stuck on the left side of the plot with all the axis labels overlapping on a single tick on the right.
ax.xaxis.set_major_locator(ticker.MaxNLocator(integer=True))
This doesn't change the axis values to integers, and also appears to cause the axis to no longer correlate with the data.

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;

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