How do I customize dual axis values? - tableau-api

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.

Related

How to scale `X` axis and include the data -- Matlab

I want to plot on X axis the points [8,16,32,64,128,512] and on Y axis the corresponding values to these points. I have done the following, but eventhough I have specified the X axis and selected the colum values for it, I am not getting the numbers [8,16,32,64,128,512] displayed on X axis.
Use xticks([8 16 32 64 128 256 512]) right after plot (or you may have to get handle of the axe) to set display ticks in X axis

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:

Set y axis max value with Matlab

I'm trying to draw plots with Matlab and the problem is that i want to fix the maximum value of y-axis to 8 . To help you understand me, look at this first example :
you can see that the maximum y value is 8. but when i try to draw this graph :
its maximum y value is 6 . i want to fix it for all examples to 8.
how can i do it?
here's my code for now :
data=importdata('C:/Users/Eden/Desktop/Calcul_accel/fichier_final.txt');
fig = figure(1);
x=data(:,2)
y=data(:,3)
p=plot(x,y)
set(p,'Color','red');
xlabel('Time(milliseconds)','FontSize',12,'FontWeight','bold','Color','b');
ylabel('Acceleration(g unit)','FontSize',12,'FontWeight','bold','Color','b')
thank you very much
Use ylim if you just want to modify the y axis.
Therefore, do this once your plot is already open:
ylim([0 8]);
This overrides the auto-scaling of the axes so that y always spans between 0 to 8.
In general, #eigenchris mentioned to use axis, which allows you to change the dynamic range of what is viewable in a plot for both the x and y axes. However, since you only want to change how the y-axis is visualized, one call to ylim is enough.

How to set x and y values when using bar3 in Matlab?

Quick version
How can I control the x- and y-values for a 3-d bar plot in Matlab?
Details
Say we have an 10 x 20 data matrix and we plot it using bar3, and we want to set the x- and y-values. For instance:
foodat = rand(10,20);
xVals = [5:14];
yVals = [-3:16];
bar3(xVals, foodat);
xlabel('x'); ylabel('y');
Is there a way to feed it the yVals as well? Otherwise the y axes always defaults to [1:N].
Note I don't just want to change the labels using XTickLabel and YTickLabel. I need to change the actual values on the axes, because I am plotting multiple things in the same figure. It isn't enough to just change how the (wrong) axis ticks are labeled. So this is different from issues like this:
How can I adjust 3-D bar grouping and y-axis labeling in MATLAB?
Other things I have tried
When I try changing the xvals with:
set(gca,'XTick', xVals)
set(gca,'YTick', yVals)
The values are taken in, but actually show up on the wrong axes, so it seems x and y axes are switched using bar3. Plus, it is too late anyway as the bar graph was already plotted with the wrong x- and y-values, so we would end up giving ticks to empty values.
Note added
Matlab tech support just emailed me to let me know about the user contributed function scatterbar3, which does what I want, in a different way than the accepted answer:
http://www.mathworks.com/matlabcentral/fileexchange/1420-scatterbar3
I found a way of doing it. Ill give you a piece of code, then you'll need to "tidy up" , mainly the axis limits and the Xticks, as bar3 does set up the Xticks inside, so if you want others you'll need to set them manually yourself.
So the trick here is to get the Xdata from the bar3 handle. The thing here is that it seems that there is a handle for each row of the data, so you need to iterate for each of them. Here is the code with the current output:
foodat = rand(20,10);
xVals = [5:14];
yVals = [-3:16];
% The values of Y are OK if called like this.
subplot(121)
bar3(yVals, foodat);
subplot(122)
h=bar3(yVals, foodat);
Xdat=get(h,'XData');
axis tight
% Widdth of barplots is 0.8
for ii=1:length(Xdat)
Xdat{ii}=Xdat{ii}+(min(xVals(:))-1)*ones(size(Xdat{ii}));
set(h(ii),'XData',Xdat{ii});
end
axis([(min(xVals(:))-0.5) (max(xVals(:))+0.5) min(yVals(:))-0.5, max(yVals(:))+0.5])
Note: Y looks different but is not.
As you can see now the X values are the ones you wanted. If you'd want other size than 1 for the intervals between them you'd need to change the code, but you can guess how probably!

Custom X axis in core plot

I have this X axis in my sample project on Core Plot and I wonder how I can customise it a little bit. As you can see it currently has only 3 values on the X axis:
But the values of the two plots I have (the black and grey ones) go far beyond the number of points in the X axis (29 against 3 points). Because of the fact that I have 3 points, only 3 values for each plot are shown.
I would like to keep displaying the remaining 3 points on the axis but accommodate all my 29 events for my plots (they could be displayed in the middle of 1 and 2 point).
How can I do this?
Increase the length of the xRange of the plot space. The value needed depends on the plot data.