Some points are not drawn in line chart using dc.js - dc.js

In line chart point for(0,0),(0,4)....etc .I mean x value as 0 and y value as 0 or x value as 0 and y value as some other number and vice-verse is not working. How to solve this using dc or d3.js.
I have tried this link https://dc-js.github.io/dc.js/examples/line.html but I didn't find any solution.

Related

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)?

Animating a datafile with gnuplot without using datablocks

If I have a datafile that is simply
x y
0 0
1 1
2 2
3 3
4 4
for example, where each line is a new timestep, how can I create an animation of this with gnuplot?
The desired animation in this case would be a point moving one unit in the positive x direction and one unit in the positive y direction each timestep.
I've only read examples of how to do this when each timestep is in a new 'datablock'. In this case, the datafile would look like
x y
0 0
1 1
2 2
3 3
4 4
which seems silly and would mean that I cannot easily use that same datafile to plot x vs y in most programs.
I've noticed an utter dearth of gnuplot examples or syntax explanations online. Am I missing some good resources?
First determine what the desired range is on x and y. You will keep this range for the entire animation.
set xrange [ xmin : xmax ]
set yrange [ ymin : ymax ]
do for [n=1:*] {
plot 'data' using 1:2 every 1::n::n with points
pause 1
}
This will plot one point every second until it runs off the end of the file. After the last line of your file you will just get an error message every second until you kill it.
Both the user manual and worked demos are on-line at gnuplot.info. They should also somewhere in the installed gnuplot package although exactly where they end up probably depends on your OS configuration.

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.

Saving a MATLAB matrix as an image to a specific size and resolution

After having read this question, I wanted to use this code to save my picture as to particular size.
I_c(:,:) = cropped_matrix(i,:,:);
set(I_c, 'PaperUnits', 'inches');
x_width = 7.25;
y_width = 9.125;
set(I_c, 'PaperPosition', [0 0 x_width y_width]);
imshow(I_c);
saveas(I_c,'fig1.pdf');
I_c represents a 2D matrix (about 40x40) of uint8's.
However, I get the error:
Error using set Invalid handle
This makes me believe that I can only use this code with figures and not matrices which contain matrices. How would I go about this?
I have looked at the API for print, as suggested as the first answer of the aforementioned linked question, but it also suggests using set and 'PaperUnits'.
Note: This question also looks at this problem but suggests the same solution.
Notes About Crowley's Answer
So I just tried the code that you have given with your answer. The .jpg being produced is the one shown below. How would I get rid of all the extra white area through code?
How would I change the colourmap of the figure being produced, to greyscale when I just use image(ImData)?
And here is how the actual figure appears:
Here is the code that I have put in:
im = image(I_c);
set(gcf,'units','inches','position',[1 2 5 5]);
set(gca,'ydir','normal','units','centimeters','position',[0 0 0.5 0.5].*get(gcf,'position')) ;
filename = strcat('slice',int2str(i),'_','bead',int2str(j),'.jpg');
saveas(im,filename);
Suppose we have matrix I_c containing values and x and y the coordinates so value I_c(ii,jj) corresponds to x(ii) and y(jj) coordinates.
Then:
ImMin=min(min(I_c)); % Find the minimum value in I_c
ImData=I_c-ImMin; % Ensure non-zero values
ImMax=max(max(ImData)); % Find maximum value in ImData
ImData=ImData./ImMax; % Ensure ImData do NOT exceed 1
image(x,y,ImData*[1 1 1]) % plot the image in greyscale
set(gcf,'units','inches','position',[1 2 5 5]) % set active figure properties
set(gca,'ydir','normal','units','inches','position',[0 0 1 1].*get(gcf,'position')) % set active axes properties
export_fig(gcf,'figure-I_c','-png','-nocrop')
'ydir','normal' parameter change default (1,1) point being in top-left corner to "normal" position in bottom-left corner.
[0 0 1 1].*get(gcf,'position) will read active figure position (here [1 2 5 5]) and after element-by-element multiplication the [0 0 5 5] is passed to the position which causes that axes fit the image.
export_fig function will create figure-I_c.png image as it is shown in Matlab figure, if -nocrop is omitted the possible white space in the edges is cropped out. This function is available from MathWorks' File Exchange.

Add mean value and n-number to nvd3 boxplot

I am using nvd3 boxplot for my charts. Is there any option to have mean as an asterisk (*) on the boxplot? Can we also have the n value above the top whisker similar to the image below.
This issue has been posted here.
Thanks in advance.
Edit
I would like to add a mean value which I calculate from the data points and not just the center of the box plot. The computed mean may not be in the center of the box plot due to outliers.
You can achieve this by doing the following algorithm:
Get all the rectangles
Find the middle point
Create a text and put it in the above calculated center
Code snippet:
function makeMarkOnMean(){
d3.selectAll(".mean").remove();//remove all * mean markers
//get all the rectangles
d3.selectAll(".nv-boxplot-box")[0].forEach(function(r){
window.setTimeout(function(){
var x = parseFloat(d3.select(r).attr("x")) + d3.select(r).attr("width")/2 - 3; //x position of the star
var y = parseFloat(d3.select(r).attr("y")) + parseFloat(d3.select(r).attr("height"))/2+12;//y position of the star
//now make the star on the above x and y
d3.select(r.parentNode).append("text").attr("class", "mean").style("font-size", "x-large").text("*").style("fill", "red").attr("x",x).attr("y", y);
},500)
});
Working code here.

Resources