设置图的轴限制

时间:2018-07-22 19:45:50

标签: matlab plot graph matlab-figure axis

我想在function SampleRightClickController($scope, $rootScope, $timeout){ $scope.gridOptions = {data: myData}; $scope.rightClick = function (event) { var scope = angular.element(event.toElement).scope() console.log('you clicked on row: ', scope.rowRenderIndex); }; }]); app.directive('rightClick', function($parse) { return function(scope, element, attrs) { var fn = $parse(attrs.rightClick); element.bind('contextmenu', function(event) { scope.$apply(function() { event.preventDefault(); fn(scope, {$event:event}); }); }); }; }); } })(); HTML: <div class="gridStyle" ui-grid="gridOptions" ui-grid-selection ui-grid-edit ui-grid-cellNav right-click="rightClick($event);"></div> 的图中设置X轴的极限。当我使用background-image: linear-gradient(to bottom, #00c76c 50%, #ffffff 50%);设置限制时(在代码中注释)。它不能正常工作。当我使用0 to 325时,情节的整个结构都会改变。任何帮助将不胜感激。enter image description here

xlim

2 个答案:

答案 0 :(得分:0)

imagesc默认将数据放在以整数1:width1:height为中心的小矩形中。您可以通过向调用添加两个向量来指定每个数据点的x和y位置:

imagesc(x,y,transpose(all_area_for_visual));

其中xy是向量,其位置沿您要放置数据的x和y轴。

请注意,xlimxticks不会更改数据的位置,只会更改所示轴的区域以及沿轴的刻度线的位置。使用xticklabels可以更改每个刻度线上显示的内容,因此可以使用它来“伪造”数据位置,但是xlim设置仍适用于实际位置,而不适用于分配的标签到刻度线。

我认为将数据绘制在正确的位置比较容易。这是一个示例:

% Fake your data, I'm making a small matrix here for illustration purposes
all_area_for_visual = min(floor(cumsum(rand(20,5)/2)),3);
times = linspace(0,500,20);      % These are the locations along the time axis for each matrix element
car_id_names = [4,5,8,15,18];    % These are the labels to put along the y-axis
car_ids = 1:numel(car_id_names); % These are the locations to use along the y-axis

% Replicate your plot
figure
imagesc(times,car_ids,transpose(all_area_for_visual));
%        ^^^    ^^^   NOTE! specifying locations
colormap("jet")
colorbar('Ticks',0:3,'TickLabels',{'Home ','Field','Bad house','Good house'})
xlabel('Time (min)')
ylabel('Car identity')
set(gca,'YTick',car_ids,'YTickLabel',car_id_names) % Combine YTICK and YTICKLABEL calls

% Now you can specify your limit, in actual time units (min)
xlim([0 325]);

答案 1 :(得分:0)

如果我说对了,您只想在all_area_for_visual上绘制部分数据,具体取决于tickLocs上的条件。因此,您应该先对数据进行条件处理,然后再对其进行绘制:

% generate the vector of x values:
tickLocs = round(linspace(1,length(final_plot_mat_missing_part(2:end,1)),8));
% create an index vector (of logicals) that marks the columns to plot from the data matix:
validX = tickLocs(tickLocs<=325);
% plot only the relevant part of the data:
imagesc(transpose(all_area_for_visual(:,validX)));
% generate the correct ticks for the data that was plotted:
timeVector = final_plot_mat_missing_part(2:end,1);
timeForTicks = (timeVector(tickLocs(validX)))./60;
xticks(tickLocs(validX));
% here you continue with setting the labels, colormap and so on...
相关问题