Highlight mean value on y-axis in bar chart - matlab

So I have a bar chart with y-axis value
y = [0:20:40:60:100]
as set by bar chart by default. Now I need to mark the mean y value of my bars, so suppose it is 54.5.
I need 54.5 on my axis.
I don't want (0, 54.5) to be marked with some sign,
I need (0, 54.5) to show the value 54.5, so that I can numerically identify the mean.
Any advicein this regard will be helpful.

%random example data
data=rand(10,1)
%create bar plot
bar(data)
%insert mean
m=mean(data)
%draw mean line
line(xlim,[m,m])
%add mean to yticks to show on axis.
set(gca,'YTick',union(get(gca,'YTick'),m))

Related

Linear and Non-linear axis in Matlab

I'm the MatLab newbie and I need some help to create a linear and non-linear axis in one chart.
I need to make chart with 2 different X-axes. One X-axis displays 1000/T at the bottom and the second X-axis displays a T at the top of the chart.
Example figure:
Do you have any idea how to solve this problem in MatLab?
Thanks.
This can be done by simply creating a second axes object at the same place as the first. Let's first create some data:
x1 = 1:0.1:3.5;
x2 = 1./x1;
y = (0.5*(x1-2)).^3;
Now we can create a normal plot with the first axes, and get the axes handle:
plot(x1,y,'-r');
ax(1) = gca;
Then we create the second axes object, at the same position as the first, and make the color none so it is transparent and the plot from below is still visible. As this adds a second Y axis too, we simply remove the Y ticks of the second axis.
ax(2) = axes('Position',ax(1).Position,'XAxisLocation','top','Color','none');
set(ax(2),'YTick',[]);
Now lets just format the second X axis as we like. Let's set the limits to the minimum and maximum of the x2 vector, and make it logarithmic:
set(ax(2),'XLim',[min(x2),max(x2)]);
set(ax(2),'XScale','log');
Now we still have the problem that the XTicks of ax(1) are also displayed at the top, and the XTicks of ax(2) are displayed at the bottom. This can be fixed by removing the box around the existing axes and creating a third axis without any ticks but with a box.
box(ax(1),'off');
box(ax(2),'off');
ax(3) = axes('Position',ax(1).Position,'XTick',[],'YTick',[],'Box','on','Color','none');
Now finally we can link the axes to be able to zoom correctly
linkaxes(ax);
And that should be it...
There is documentation for having a graph with two y-axes on the Mathworks website . .
http://de.mathworks.com/help/matlab/creating_plots/plotting-with-two-y-axes.html
It should be trivial to covert the concepts to the x-axis.

How do you accurately set the offset of an axisLabel in CorePlot?

Problem Statement:
A bar plot in created with CorePlot has a Y-axis that features a dynamic range. The minimum value of this range is presumed to be <= 0. The maximum value of the range is presumed to be > 0.
The bar plot features custom X-axis labels which have an offset to distance themselves from the 0 line of the Y-axis. (label.offset)
However, because the exact location of the 0 line may change during runtime, a static value to offset the X-axis labels is not sufficient.
Question:
What is the appropriate way to accurately set the offset of Axis labels, when axis parameters change at runtime?
Screenshot attached to show problem. Labels should be below the ($200,000) line, but because the top end value is dynamic, they move up and down.
http://i.imgur.com/jdwy1c2.png
From the linked picture, it doesn't look like you're drawing the axis line. Use axis constraints to hold the x-axis at the bottom of the plot area. If you do want to draw an axis line, e.g., at y = 0, add a second x-axis. Use one to draw the axis line and the other to position the labels. Set all of the line style properties of the second axis to nil so it doesn't draw any lines and use constraints to hold it at the bottom of the plot area.

plot bar and fill according to % correct

I have n sensors. For every round 1 to N I am going to see how many sensors are alive and draw it as a bar or box. the height of the bar will be the number of sensors.
Also
From the n sensor x will be correct y different by 10 values and z wrong. Can we display that by % of the bar colored according to x y z (green blue red for example)?
in addition if the mean value is correct i want the contour of the bar to be blue else to be red.
solution was to save the data in array and then plot

Core Plot Bar Chart Columns

Is it possible to set some padding between the first bar and the Y axis?
The last bar is always a few pixels away from the right margin of the plot but the first column always appears cut by the Y axis
Adjust the xRange of your plot space. Decrease the starting location and increase the length.

How do I edit the axes of an image in MATLAB to reverse the direction?

I would like to edit the axes in my series of images being displayed.
This is what my image looks like:
As you can see, it ranges from 0 to about 500 from top to bottom. Can I invert that?
Plus, I want to mirror the image being shown, so that it starts from left to right... or, if it's possible, to let the axes show from right to left.
To reverse an axis, you can set the 'XDir' or 'YDir' property of the current axes to 'reverse':
set(gca,'XDir','reverse'); %# This flips the x axis
Keep in mind that flipping an axis in this way flips everything in the plot as well. This probably isn't what you want to do for the y axis. You probably just want to flip the y axis labels, which you can do by modifying the 'YTickLabel' property in the following way:
yLimits = get(gca,'YLim'); %# Get the y axis limits
yTicks = yLimits(2)-get(gca,'YTick'); %# Get the y axis tick values and
%# subtract them from the upper limit
set(gca,'YTickLabel',num2str(yTicks.')); %'# Convert the tick values to strings
%# and update the y axis labels
Im = imread('onion.png');
Im = flipdim(Im ,1); % vertical flip the image.
axis xy; %set the xy to be at (0,0), this flips the image back again.
And whoop dee doo the image now have an y axis with the range from bottom to top!
How can I reverse the y-axis when I use the IMAGE or IMAGESC function to display an image in MATLAB? Another solution from mathworks
I found gnovice's answer helpful but it needed some tweaks for me. I think the following is a more general way to reverse the labels on the y axis. Simply sort the y tick numbers in descending order and relabel.
yTicks = get(gca,'YTick');
yTicks_reverse = sort(yTicks,2,'descend');
set(gca,'YTickLabel',num2str(yTicks_reverse.'));
I was redirected here from a duplicate question:
Flipping axis ticks
What 'ale' wanted to do there was just to flip the y-axis direction to be top down. If that is the only thing needed and nothing else, I would use:
axis ij