c3js: How to make not equally spaced Y axis tick? - axis

I'm trying to make not equally spaced Y axis tick in c3js.
For example, this graph has equally spaced tick. (0,20,40...)
I want to set a graph not equally spaced axis tick like 0,30,45,55...
How can I get this?

You can refer https://c3js.org/reference.html#axis-y-tick-values for your use case.
It allows you to provide the tick values, but you should take care of the values going out of bound than the max bar value and the spacing between them.

Related

How do I customize dual axis values?

I want to plot 2 variables in my worksheet.X variable vs Y variable. The Y variable is composed of 3 sub-variables y1,y2,y3 which when summed up result to Y. I have expressed y1,y2,y3 as percentages of Y say Y=45(100%) and y1=35%,y2=40%,y3=25%.How do I plot X vs Y with the Y axis value being 45 and not 100%?
I have been to plot the measure values of Y(y1,y2,y3) but now the axis values are automatically generated from 0 to 100%. What I want is the real axis values to be displayed 0 to 45.
I want the axis to be real values of Y(45) but the sub_variables (y1=35%,y2=40%,y3=25%)
There are a couple of things you can do here.
Click on the secondary axis and select "Synchronize axis". This
will ensure that the secondary axis is tied to the scope of the
primary axis.
You can manually edit either/both axis by right clicking on them and setting the axis values manually.
Beyond this, it might be how you are setting up your viz. If you could provide a picture/sample data it would be helpful.

How to set matlab xticks equal distance with unequal numerical spaces?

I am plotting data which is polynomial but I would like to show it on a straight line so that it is clearer.
I want the x-axis tick marks to show N^2 where N is the tick location. I also want the actual ticks on the graph to be evenly spaced even though the numbers aren't.
I tried to change the ticks using
xtick_squared = (0:10:100).^2
set(gca,'xTick',xtick_squared,'xTickLabel',xtick_squared)
but it gives this
How can I display them each being even spaced while reatining their values as well as adjusting the data?
This should work fine:
x = 0:10:100;
y = (x .^ 2) + 5;
labs = sprintfc('%d',x.^2);
plot(x,y);
set(gca,'XTickLabel',labs);
Actually, it's all about changing the tick labels without changing the ticks themselves. Here is the final output:
You can specify the location of x-ticks and then rename them.
Here is the code example:
x=[0,10,20,30,40,50].^2;
plot(x,x)
set(gca,'XTick',linspace(0,2500,6),'XTickLabels',num2cell(x))
P.S.: Note, that your actual data is plotted on evenly spaced grid. I've just renamed the ticks' names.
Edit: if you want to plot your actual data, you need to scale x-axis correspondingly. If you want to plot(x,x) you need to call plot(sqrt(x),x) instead:
x=[0,10,20,30,40,50].^2;
plot(sqrt(x),x)
set(gca,'XTick',linspace(0,2500,6),'XTickLabels',num2cell(x))

How to have a log scale plot so that the smallest value on the vertical axis is a power of 10

I have the following logarithmic plot shown below:
I want to change this plot so that the "x axis" is such that the vertical value lies at the smallest possible power of 10. What I mean by this is that I would like to make sure that the horizontal axis seen at the bottom of the plot is perhaps y = 10e-2 such that the rightmost group of bars in the above plot can be above the "x axis". I tried 'xaxislocation' but it doesn't work. In hindsight, I suppose the y=10e0 line is not the x axis anyway.
% plot group_err
data_names = cell(1,8);
data_names{1}='1'; data_names{2}='2';
data_names{3}='3'; data_names{4}='4';
data_names{5}='5'; data_names{6}='6';
data_names{7}='7'; data_names{8}='8';
h = bar(group_err);
grid on;
set(gca,'xticklabel',data_names,'YScale','log','FontSize',14);
ylabel('Error rate (%))','FontSize',14);
xlabel('Dataset','FontSize',14);
title('Error rate of sequential algorithms','FontSize',14);
ylim([0.01 100]);
group_err:
79.0407673860911 80.6235000000000 80.3837000000000
28.2600000000000 24.3600000000000 25.0200000000000
2.18055555555556 1.44290190000000 1.92145600000000
34.1692954784437 14.9053400000000 17.9127200000000
0.0551724137931035 0.0298850500000000 0.0459770500000000
33.2005921539600 22.4352400000000 25.6802200000000
0.0979391960824322 0.0685568400000000 0.155070440000000
Now that we've seen your edit, that's very straight forward. Simply find whatever y value is the smallest and you need to round this down so that the resulting value is a power of 10 and is smaller than the smallest y value you're looking at.
To do this, you want to the floor of the following relationship where given your minimum value ymin, it satisfies this relationship:
10^floor(x) = ymin
Re-arranging this equation by taking the log of both sides, we get:
x = log(ymin) / log(10)
... and we now take the floor of x to get what you need. Take special note that you need to take the floor as it rounds down to minus infinity. Don't use fix as this rounds towards 0 so for negative values, this will add 1 to negative values and not what you want. Specifically, this will ensure that you find the smallest power x that respects negative powers when the above relationship is less than 1.
The value of x serves as the smallest power of 10 that satisfies what you need. You will the need to take 10^x to complete the task. This is the smallest power of 10 that will serve as the horizontal axis of your plot. You then use ylim to limit the vertical axis so that you see what the smallest and largest values you have. Because you are using a semi-logarithmic plot, to do what you need you must specify these values as powers of 10. This is the whole reason why we need to determine the smallest power of 10 to serve as the minimum limit or the x axis of your data.
Therefore, assuming you have your plot already open, simply do the following:
x = floor(log(min(y)) / log(10));
ylim([10^x max(y)]);
ylim takes two values: The minimum value and maximum value of the y axis you would like to see. I've made sure that the largest value to visualize is just the largest value in your data itself.
what you want in to change the 'BaseValue' property of your bar plot, in your case would be:
set(h,'BaseValue',0.01)
You will get something like this:

plotting in matlab, increase number of divisions on Xaxis

I want to increase number of tickmarks on the X-axis in a Matlab Dft graph (magnitude vs. frequency). The precision is OK, but I'd like to increase the number of values displayed on the X-axis.
To set the XTick property of the current axis (gca, get current axis), use:
set(gca,'XTick',tickVector);
with tickVector being a vector containing the desired tick positions.
You can achieve this by turning on minor tickmarks.
set(gca,'XMinorTick','on');
This saves you from determining explicit tick mark positions when you just want more.

Core Plot :Move only Data

I have created a scatter graph with three plot spaces. One for two y-axis each and one for the x-axis. I am able to show data for both y-axis. However now i want to move only the data,i.e. two line and not the two y-axis.Only the data and x-axis should move.
I have tried allowUserinteraction property. However is I enable it for x-axis, x axis moves without the data. If i enable it for both/either of axis, y axis also moves with data and scale of y-axis is not visible all the time. Can someone help pleas.e This is my first work with core plot.
I will add code if required.
Thanks
Since each plot space has both x and y ranges, I would just use two plot spaces for this situation. Use the same xRange for both plot spaces and assign the x-axis to one of them.
The easiest way to make them scroll only in the X direction is to set the globalYRange to the same range as the yRange for both plot spaces. Set allowsUserInteraction to YES for both plot spaces. If you need to change the yRange later, set the globalYRange to nil before you change the yRange and reset it afterwards. If you ever update the X range manually, be sure to always set it on both plot spaces.