I am attempting to create a line graph with an inverted y-axis. The y-axis I was hoping to create would have a maximum value of 1 (top) and a minimum axis value of 5 (bottom). I have not been able to find how to perform this operation in jasper report, how can I do it?
I just make negative numbers, but that´s not the way I want to do it
2 at top, 20 at bottom (not negatives) Reference: 2
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:
My x-axis is latitudes, y-axis is longitudes, and z-axis is the hist3 of the two. It is given by: z=hist3(location(:,1:2),[180,360]), where location(:,1) is the latitude column, and location(:,2) is the longitude column.
What I now want is, instead of plotting on a self-created XY plane, I want to plot the same on a worldmap. And instead of representing the frequency of each latitude-longitude pair with the height of the bars of hist3, I want to represent the frequency of each location by a heat map on top of the world map, corresponding to each latitude-longitude pair's frequency on the dataset. I have been searching a lot for this, but have not found much help. How to do this? I could only plot the skeleton of the worldmap like this:
worldmap world
load geoid
geoshow(geoid, geoidrefvec, 'DisplayType', 'texturemap');
load coast
geoshow(lat, long)
I don't know what the colour is being produced based on.
Additionally, if possible, I would also like to know how to plot the hist3 on a 3D map of the world (or globe), where each bar of the hist3 would correspond to the frequency of each location (i.e., each latitude-longitude pair). Thank you.
The hist3 documentation, which you can find here hist3, says:
Color the bars based on the frequency of the observations, i.e. according to the height of the bars. set(get(gca,'child'),'FaceColor','interp','CDataMode','auto');
If that's not what you need, you might wanna try it with colormap. More info about it here colormap. I haven't tried using colormap on histograms directly, so If colormap doesn't help, then you can try creating a new matrix manually which will have values in colors instead of the Z values the histogram originally had.
To do that, you need to first calculate the maximum Z value with:
maxZ=max(Z);
Then, you need to calculate how much of the colors should overlap. For example, if you use RGB system and you assign Blue for the lowest values of the histogram, then Green for the middle and Red for the High, and the green starts after the Blue with no overlap, than it will look artificial. So, if you decide that you will have, for example overlapping of 10 values, than, having in mind that every R, G and B component of the RGB color images have 255 values (8 bits) and 10 of each overlap with the former, that means that you will have 255 values (from the Blue) + 245 values (From the Green, which is 255 - 10 since 10 of the Green overlap with those of the Blue) + 245 (From the Red, with the same comment as for the Green), which is total amount of 745 values that you can assign to the new colored Histogram.
If 745 > maxZ there is no logic for you to map the new Z with more than maxZ values. Then you can calculate the number of overlaping values in this manner:
if 745 > maxZ
overlap=floor(255- (maxZ-255)/2)
end
At this point you have 10 overlapping values (or more if you still think that it doesn't looks good) if the maximum value of the Z is bigger than the total amount of values you are trying to assign to the new Z, or overlap overlapping values, if the maximum of Z is smaller.
When you have this two numbers (i.e. 745 and maxZ), you can write the following code so you can create the newZ.
First you need to specify that newZ is of the same size as Z. You can achieve that by creating a zero matrix with the same size as Z, but having in mind that in order to be in color, it has to have an additional dimension, which will specify the three color components (if you are working with RGB).
This can be achieved in the following manner:
newZ=zeros(size(Z),3)
The number 3 is here, as I said, so you would be able to give color to the new histogram.
Now you need to calculate the step (this is needed only if maxZ > The number of colors you wish to assign). The step can be calculated as:
stepZ=maxZ/Total_Number_of_Colors
If maxZ is, for example 2000 and Total_Number_of_Colors is (With 10 overlaping colours) 745, then stepZ=2.6845637583892617449664429530201. You will also need a counter so you would know what color you would assign to the new matrix. You can initialize it here:
count=0;
Now, finally the assignment is as follows:
For i=1:stepZ:maxZ
count=count+1;
If count>245
NewZ(Z==stepz,3)=count;
elseif count>245 && count<256
NewZ(Z==stepz,3)=count;
NewZ(Z==stepz,2)=count-245;
elseif count>255
NewZ(Z==stepz,2)=count-245;
elseif count>500 && count<511
NewZ(Z==stepz,2)=count-245;
NewZ(Z==stepz,1)=count-500;
else
NewZ(Z==stepz,1)=count-500;
end
end
At this point you have colored your histogram. Note that you can manually color it in different colors than red, green and blue (even if you are working in RGB), but it would be a bit harder, so if you don't like the colors you can experiment with the last bit of code (the one with the for loops), or check the internet of some other automatic way to color your newZ matrix.
Now, how do you think to superimpose this matrix (histogram) over your map? Do you want only the black lines to be shown over the colored histogram? If that's the case, than it can be achieved by resampling the NewZ matrix (the colored histogram) with the same precision as the map. For example, if the map is of size MxN, then the histogram needs to be adjusted to that size. If, on the other hand, their sizes are the same, then you can directly continue to the next part.
Your job is to find all pixels that have black in the map. Since the map is not binary (blacks and whites), it will be a bit more harder, but still achievable. You need to find a satisfactory threshold for the three components. All the lines under this threshold should be the black lines that are shown on the map. You can test these values with imshow(worldmap) and checking the values of the black lines you wish to preserve (borders and land edges, for example) by pointing the cross tool on the top of the figure, in the tools bar on every pixel which is of interest.
You don't need to test all black lines that you wish to preserve. You just need to have some basic info about what values the threshold should have. Then you continue with the rest of the code and if you don't like the result so much, you just adjust the threshold in some trial and error manner. When you have figured that this threshold is, for example, (40, 30, 60) for all of the RGB values of the map that you wish to preserve (have in mind that only values that are between (0,0,0) and (40,30,60) will be kept this way, all others will be erased), then you can add the black lines with the following few commands:
for i = 1:size(worldmap,1)
for j = 1:size(worldmap,2)
if worldmap(i,j,1)<40 && worldmap(i,j,2)<30 && worldmap(i,j,3)<60
newZ(i,j,:)=worldmap(i,j,:)
end
end
I want to note that I haven't tested this code, since I don't have Matlab near me atm, so It can have few errors, but those should be easily debugable.
Hopes this is what you need,
Cheers!
All
I have a control chart, with on the X-axis a time period, and the Y-axis the value of the measure (I'd like to plot all the points in a control chart).
However, I have 2 different values as a measure, which have the exact same date (up to a second match) but different measure values.
When I plot this on a control chart, instead of having 2 points in the control chart with value 500 and 550 for example - it gives me one point with a value of about 200.
It also gives a notification that there is a NULL value in this axis, which points to the X-axis where 2 records have the exact same date.
Any idea what I can do to make this correct - or make tableau draw the measure points correctly?
Thanks in advance!
It's difficult to answer without seeing more detail about your problem, but this sounds like a good candidate for a blended axis. (multiple measures sharing a single axis)
The easiest way to do this is to put your (probably continuous) datetime field on the row axis and one of your measures on the row axis to see one of then control plots. Then drag the second measure to the Y-axis until you see a little translucent two bar icon to indicate that you are adding a second measure to that axis, at which point you can release the pointer and you should see a two plots on the same axis.
If the scales for the two measures are radically different, you can instead drag the second measure to the right side instead to get a dual axis.
I read now this tutorial fo developers:
https://developers.google.com/chart/interactive/docs/gallery/columnchart
Using object hAxis and parametr direction i try to show only positive axis of my chart.
Also i wanna, that my axis be only integer numbers, now it is 0.5, 1, 1.5
Thanks!
vAxis: {viewWindowMode: "explicit", viewWindow:{ min: 0 }}
The direction option only controls the direction of the axis (left-to-right, or right-to-left), not what values are shown. Use the hAxis.viewWindow.min and hAxis.viewWindow.max options to control the range of values displayed on the axis. Setting hAxis.viewWindow.min to 0 will prevent any negative numbers from showing up.
Keep in mind that the columns are centered on their axis values, so if you have any columns at 0, you have to give them a bit of space to the left of 0 to draw all of the columns. Similarly, they need a bit of space to the right of the max value to fit all of the columns.
By default, the ColumnChart will try to place 5 axis tick marks (which you can change by setting the hAxis.gridlines.count option), evenly spaced throughout your data. This can end up with some rather odd results. Sometimes you end up with decimals in the labels that can be safely ignored (this is especially true when your axis spans a large numeric distance); in this case, you can set the hAxis.format option to drop decimals (eg, '#,###'). If your data spans a smaller range, you might be better served specifying the hAxis.ticks option, which takes an array of values to place tick marks at.