plotting some figures and in x-axis Ipython - ipython

I am plotting some figures and in x-axis, and Ipython gives me format like 0 1 2 3 4 5 6 7 +2004e3 which means 0=2004 and 1=2005.
But i want vice versa. Like 2004 2005 2006 2007... How can I accomplish this?

Related

Histogram rebinning in Matlab 2020a, when I don't have a Matlab histogram object

I have two vectors that describe a histogram: bin values/labels and bin count.
I'd like to import those into a Matlab histogram object so that I can change parameters more easily, such as the number of bins.
Here is a simplification what I have:
Center bin values:
BinValues(1:21) = [-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10];
and count values per bin
CountValues(1:21) = [ 16 12 3 21 7 8 2 6 0 3 4 6 1 8 3 25 16 5 7 10 16];
My actual histogram has 800000 bins, and I want to vary the number of bins.
In my simplified example above, it would be something like reducing the bins from 21 to 15 or 21 to 11.
What I have can be graphed as a simple bar graph.
bar(BinValues,CountValues);
But, if I want to experiment with different numbers of bins, I think it would be best to use the histogram function/object in Matlab, but I'm not sure how I do this from what I have.
OK Update:
I tried this:
h=histogram('BinEdges',[-10.5:10.5] , 'BinCounts', CountValues);
Now I have a nice histogram, but if I use fewerbins(h), I get an error saying I can't do that while BinCountsMode is in "manual". If I modify it to be in "auto" mode, then my original histogram disappears.
The brute force solution would be to generate a huge array with repeated values as dictated by binCount values, but that seems like a dumb way to solve this problem.

How to draw a Histogram in Matlab

I have a set of around 35000 data. These data are the signal strengths received only from a single location for different time interval of time. I want to plot a Histogram using these data. My X-axis will give the information about "Signal Strengths" and my Y-axis will give the information about "Probability". My histogram will consists of different bars which will give information about the signal strength and probabilities.
For example, suppose I have the following data
a= [ 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 3 4 4 4 5 6 6 6 6 6 6 6 6 6 6 6]
How can I plot the graph using data at X-axis and Probability at Y-axis? Any help will be appreciated. Thanks!
This should work just fine if you don't want to use some predefined functions:
una=unique(a);
normhist=hist(a,size(unique(a),2))/sum(hist(a));
figure, stairs(una,normhist)
Una has only the unique values of a, normhist is now between 0 and 1 and it's the probability of occurring of the individual signal because you divide it by the number of elements included in the data.

Matlab: Bar chart x-axis labels missing

I'm using the following code to create a bar chart in matlab.
a = [1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9]
bar(a)
set(gca,'XTickLabel',{'one','two','three','four','five','six','seven','eight','nine','zero','one','two','three','four','five','six','seven','eight','nine'})
Code works fine except that x-axis labels don't appear on their corresponding position on the x-axis. How do I resolve this issue?
When you set XTickLabel, you are telling Matlab to replace the text where each tick currently is with new text that you provide. If you run only the first two lines, you will see that Matlab by default has put XTicks on 0:2:20. You can resolve the issue by first telling Matlab to put ticks for each individual bar, and then re-labeling these ticks:
a = [1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9]
bar(a)
set(gca, 'XTick', 1:length(a))
set(gca,'XTickLabel',{'one','two','three','four','five','six','seven','eight','nine','zero','one','two','three','four','five','six','seven','eight','nine'})
You will have a pretty cluttered x-axis at this point...you would want to look into rotating the XTickLabels with the rotateXLabels function from FileExchange or with the built-in functionality on Matlab14b and later.

Draw lines between coordinates of a matrix in MATLAB

I would like to draw lines between the coordinates of the matrix below and then plot it, it should become an F.
F = ([0 2 2 7 7 2 2 8 8 0 0;0 0 8 8 10 10 14 14 16 16 0])
How can I do this?
You should simply be able to do this with
plot(F(1,:),F(2,:))
the style that you are plotting the data with has many options that you can refer to here http://www.mathworks.co.uk/help/matlab/ref/plot.html
Have you tried this?
plot(F(1,:),F(2,:),'k-.')
I dont have matlab here, but this must work!

Set x-axis to non-monotonic values and avoid scaling

I use matlab to plot a graph where instead of having x-axis increase monotonically, I have my own values. eg 5 14 8 9 12 7 etc.I use set (gca,'XTickLabel',num2str(mydata)) which generally works. However, when mydata is more than four or five digits, Matlab scales the graph and thus x-axis values no longer correspond to their intended points. Any ideas on how to prevent this scaling? To clarify, when I make the figure larger, it shows the plot as it should.
The problem is in your num2str() conversion:
mydata = 1:10;
num2str(mydata)
ans =
1 2 3 4 5 6 7 8 9 10
This means, that each tick will be labelled with this long 1 by n char array. The axes will then be resized to fit the labels inside the figure.
A solution is to create one label per row of a char array:
reshape(sprintf('%2d',mydata),2,[])'
ans =
1
2
3
4
5
6
7
8
9
10
Sort of solution is to write set(gca,'xtick',1:myDataVectorLength) before set (gca,'XTickLabel',num2str(mydata))