w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
matlab, plot multiple matrices different colors
Just use the syntax plot(mat1, 'r'); hold on; plot(mat2, 'g'); However, instead of hardcoding the values, compute them from your own table: mystyles = {'r-', 'g:', 'k|'}; plotstyle = mystyles{mod(plotnum, length)+1}; plot(values, plotstyle); I've used mod to circle back around the beginning. You can use whatever logic you want, including combining different colors and styles with two different pieces of arithmetic.

Categories : Matlab

insert string within marker of matlab plot
Use text and properly adjust the text properties to suit your purpose. You may have to play with the marker size and text alignment, but it's a fairly straightforward process. For example: % plot the data figure d3 = [1, 3, 5, 6, 8, 9]; n = 1:numel(d3); plot(n,d3, '-ob','markersize',10,'markerfacecolor','w'); % step through the points in d3 and display a text label for each of them for idx = 1:numel(d3) text(n(idx),d3(idx), num2str(d3(idx)),... 'FontSize',8,... 'HorizontalAlignment','center'); end

Categories : Matlab

How to plot multiple figures in a for loop in matlab
You can create new figures by using the figure function. figure plot([0 1],[0 .3]); figure plot([0 1],[0 0.6]); figure plot([0 1],[0 0.9]); Or you can put multiple axes in the same figure using the subplot function; subplot(3,1,1); plot([0 1],[0 .3]); subplot(3,1,2); plot([0 1],[0 .6]); subplot(3,1,3); plot([0 1],[0 .9]); Or you can plot 3 lines in the same axis by using the hold function plot([0 1],[0 .3]); hold on; plot([0 1],[0 .6]); plot([0 1],[0 .9]);

Categories : Matlab

How to update multiple graphs from one plot in one statement in Matlab?
Try redrawing the plot: xcoor = cellfun(@horzcat, get(p, 'XData'), {2; 3}, 'UniformOutput', false); ycoor = cellfun(@horzcat, get(p, 'YData'), {2; 3}, 'UniformOutput', false); c = [xcoor; ycoor]; plot(c{:})

Categories : Matlab

Matlab: Plot multiple anonymous functions using fplot
If you really must do this: >> f = @sin; >> g = @cos; >> hold on >> cellfun(@(func) fplot(func, [-3, 3]), {f, g}) This applies the function handle @(func) fplot(func, [-3, 3]) to each of the elements in the cell array {f, g}. Since I also called hold on, both functions will show up in the resulting plot. If you don't call hold on, you'll just see cos(x) since that's the last function that was plotted. You cannot hold function handles in standard MATLAB arrays. You should use cell arrays for that. If you read the error message you get from trying to put a function handle into a standard array you get an informative message about what to do: >> [f, g] Error using horzcat Nonscalar arrays of function handles are not allowed; use cell arrays instead.

Categories : Matlab

Using "imhist" function in Matlab to plot multiple histograms on the same figure
If you want both on the same axes and you don't mind loosing the lower bar, try this (I don't have the Image Toolbox right now, so I haven't tested it): a=imread('image1.jpg') agray=rgb2gray(a) b=imread('image2.jpg') bgray=rgb2gray(b) [counts,x] = imhist(agray) stem(counts,x,'b') hold on [counts,x] = imhist(bgray) stem(counts,x,'r')

Categories : Matlab

Matlab: Saving plot images, override plot.m
you can simply use the print command and save them into a directory that you can also make using the mkdir command. Sample code clc; close all; clear all; x = 1:10; y = x.^2; plot(x,y) if exist('plots','dir') ~= 7 mkdir('plots'); % make directory if it does not exist end print -dpdf ./plots/jawn.pdf Read the print documentation, to learn how to print in other file formats Also, I would not suggest overriding the plot command, and you will likely not be able to find the source code for plot.m because that is proprietary MATLAB code

Categories : Matlab

Legend does not match plot lines on MATLAB plot
The display of the red line as a full line is curious. In any case it's related to your plotting a vector against a scalar. This will plot equal length vectors and generate the behavior you expect: plot(y, g, '-k', y, P1*ones(1,length(y)), ':r', y, P3, '--b');

Categories : Matlab

Matlab; Scatter plot- shift the plot
Use the axis command: >> axis([0 1 0 1]); to set the limits of the axis (the range displayed). See axis doc for more info.

Categories : Matlab

plot matrix with three colors
Your question is not very clear, but maybe something like this? #some data set.seed(42) dat <- matrix(sample(c("A","B",NA), 25, TRUE), 5) # [,1] [,2] [,3] [,4] [,5] # [1,] NA "B" "B" NA NA # [2,] NA NA NA NA "A" # [3,] "A" "A" NA "A" NA # [4,] NA "B" "A" "B" NA # [5,] "B" NA "B" "B" "A" #reshape, so ggplot likes it library(reshape2) df <- melt(t(dat)) df$value <- as.character(df$value) #to be able to plot NA values df$value[is.na(df$value)] <- "NA" library(ggplot2) ggplot(df, aes(x=Var1, y=-Var2, fill=value)) + geom_tile() + scale_x_continuous(expand=c(0,0), breaks=seq_len(max(df$Var1))) + scale_y_continuous(expand=c(0,0), breaks=-seq_len(max(df$Var2)), labels=seq_len(max(df$Var2))) + scale_fill_manual(v

Categories : R

How to plot heatmap colors in 3D in Matplotlib
Yes, something like this: update here is a version with a colorbar. import numpy as np from pylab import * from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt def randrange(n, vmin, vmax): return (vmax-vmin)*np.random.rand(n) + vmin fig = plt.figure(figsize=(8,6)) ax = fig.add_subplot(111,projection='3d') n = 100 xs = randrange(n, 23, 32) ys = randrange(n, 0, 100) zs = randrange(n, 0, 100) colmap = cm.ScalarMappable(cmap=cm.hsv) colmap.set_array(zs) yg = ax.scatter(xs, ys, zs, c=cm.hsv(zs/max(zs)), marker='o') cb = fig.colorbar(colmap) ax.set_xlabel('X Label') ax.set_ylabel('Y Label') ax.set_zlabel('Z Label') plt.show() looks like: update Here is an explicit example of coloring your data points by some 4th dimensional attribute. import numpy as np f

Categories : Python

python: how to plot one line in different colors
See the answer here to generate the "periods" and then use the matplotlib scatter function as @tcaswell mentioned. Using the plot.hold function you can plot each period, colors will increment automatically.

Categories : Python

Spaghetti plot with different colors for each subject in ggplot2
Using ggplot2 comment gives you the right answer : You should coerce b to a factor and it as a color aes. Using lattice no need to coerce b to factor: library(lattice) xyplot(c~a,data =x,groups=b,type='l') Or using latticeExtra to get ggplot2 theme: library(latticeExtra) xyplot(c~a,data =x,groups=b,type='l', par.settings = ggplot2like(),axis=axis.grid)

Categories : R

matplotlib - change marker color along plot line
I believe you can achieve this with ax.scatter: # The data x = np.linspace(0, 10, 1000) y = np.sin(2 * np.pi * x) # The colormap cmap = cm.jet # Create figure and axes fig = plt.figure(1) fig.clf() ax = fig.add_subplot(1, 1, 1) c = np.linspace(0, 10, 1000) ax.scatter(x, y, c=c, cmap=cmap) Scatter accepts c as a sequence of floats which will be mapped to colors using the cmap. Using timeit I get a 10 fold decrease in time (about 1.25 secs for the original method and 76.8 ms here)

Categories : Python

Changing marker style in scatter plot according to third variable
The problem is that marker can only be a single value and not a list of markers, as the color parmeter. You can either do a grouping by marker value so you have the x and y lists that have the same marker and plot them: xs = [[1, 2, 3], [4, 5, 6]] ys = [[1, 2, 3], [4, 5, 6]] m = ['o', 'x'] for i in range(len(xs)): plt.scatter(xs[i], ys[i], marker=m[i]) plt.show() Or you can plot every single dot (which I would not recommend): x=[1,2,3,4,5,6] y=[1,3,4,5,6,7] m=['k','l','l','k','j','l'] mapping = {'j' : 'o', 'k': 'x', 'l': '+'} for i in range(len(x)): plt.scatter(x[i], y[i], marker=mapping[m[i]]) plt.show()

Categories : Python

how to add marks and change colors along with points in the hexbin plot
I suggest you look at grid.hexagons, i.e., ?grid.hexagons in R. The help page gives some good examples of how to play around with the color functions. Also, this question has been more or less answered before: specific colours are required within Hexbin package? so hopefully that helps you out. I wasn't able to figure out how to add the text to the plot yet though.

Categories : R

matplotlib: changing stem plot legend colors
The default for legend is to display two markers. You can change this with the argument numpoints = 1. Your legend command is using the markers, not the lines as inputs by using plot[0]. Unfortunately, the stems are not supported artists for legend so you need to use a proxy artist. Here's an example: import pylab as plt from numpy import random plots, legend_names = [], [] x1 = [10,20,30] y1 = [10,20,30] # some fake data x2 = [15, 25, 35] y2 = [15, 25, 35] x_vars = [x1, x2] y_vars = [y1, y2] legend_names = ['a','b'] # create figure plt.figure() plt.hold(True) plots = [] proxies = [] for x_var, y_var in zip(x_vars, y_vars): markerline, stemlines, baseline = plt.stem(x_var, y_var) plots.append((markerline, stemlines, baseline)) c = color = random.rand(3,1) plt.setp(

Categories : Python

Matlab density plot, Heat map, Matlab
You can control the colour of each point like so: scatter(x1, y1, [], C) where C is the same size as your x1 and y1 matrices. Now if you describe the rules of how you want this heatmap colour modulation to happen, we can help you construct C from x1 and y1...

Categories : Matlab

Matlab get an average plot out of several plot
Assuming you don't have access to the original data you used for doing the plots: plot_data = get(get(gca,'Children'),'YData'); % cell array of all "y" data of plots average = mean(cell2mat(plot_data)); In order for this to work, you have to use this code right after doing the plots, that is, without plotting to any other figure (gca is a handle to the current axes).

Categories : Matlab

How to highlight a particular marker on a multiple marker map
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Google Maps Multiple Markers</title> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> </head> <body> <div id="map" style="width: 500px; height: 400px;"></div> <script type="text/javascript"> var locations = [ ['Coogee Beach', -33.923036, 151.259052, 5], ['Bondi Beach', -33.890542, 151.274856, 4], ['Cronulla Beach', -34.028249, 151.157507, 3], ['Manly Beach', -33.80010128657071, 151.28747820854187, 2], ['Maroubra Beach', -33.950198, 151.259302, 1] ]; var lat_center = -33.923036, long_cen

Categories : Google Maps

ggplot2 stats="identity" and stacking colors in bar plot gives "striped" bar chart
One way would be to order your data by category2. This can be done also inside ggplot() call. ggplot(d[order(d$category2),], aes(x=category1, y=qty, fill=category2)) + geom_bar(stat="identity")

Categories : R

LINES(M) unique colors Matlab
The lines color map has only 7 unique colors (as you have already spotted). If you need more than 7 unique colors, you'll have to create a map by yourself. One option is using rand: >> rCmap = rand( n, 3 ); % create a random map with n colors - usually unique.

Categories : Matlab

Changing matlab background colors
Turns out that the commands were working within MATLAB, they just weren't working on the printed file because, according to http://www.mathworks.co.uk/help/matlab/ref/print.html.... By default, MATLAB changes the figure background color of printed output to white, but does not change the color of uicontrols. If you have set the background color, for example, to match the gray of the GUI devices, you must set InvertHardcopy to off to preserve the color scheme. To set InvertHardcopy on the current figure, use the command: set(gcf,'InvertHardcopy','off') So once I set set(gcf,'InvertHardcopy','off'), everything was peachy... thanks in particular to Molly, who put me on the right track...

Categories : Matlab

MATLAB: generating a colormap given three colors
I would use linspace: cmap=[linspace(oldRed,newRed,steps)' ... linspace(oldGreen,newGreen,steps)' ... linspace(oldBlue,newBlue,steps)']; And then for do the same for your next step, and concatenate them: cmap_full = [cmap;cmap2];

Categories : Matlab

how to fill colors between contours in matlab
This can be done by using the get command to get individual components from the graph. For example: [x, y, z] = peaks; % Generate some data figure; surf(x, y, z); % Show figure;[c, h] = contourf(x, y, z, [0 0]); % Build and show contour plot patches = get(h, 'children'); % Get different patches set(patches(1), 'facecolor', 'r') % Colour one red

Categories : Matlab

Matlab two different colors in same line in legend
Probably you mistyped tex string: figure hold on line1H=plot(1:10,1:10); line2H=plot(1:10,2*(1:10),'r'); leg{1} = 'BlackText {color{blue}line1} BlackAgain'; leg{2} = 'BlackText {color{red}line2} BlackAgain'; legend([line1H,line2H],leg{:}) Generates:

Categories : Matlab

How do I plot multiple data subset forecast predictions onto a single plot
This is answered in another post Is there an easy way to revert a forecast back into a time series for plotting? This was initially posted as two unique questions, but they have the same answer. The core question being addressed is "how to restore the original time stamps to the forecast data". What I have learned with trial and error is "configure, then never loose the time series attribute" by applying these steps: 1: Make a time series Use the ts() command and create a time series. 2: Subset a time series Use 'window()' to create a subset of the time series in 'for()' loop. Use 'start()' and 'end()' on the data to show the time axis positions. 3: Forecast a time series Use 'forecast()' or 'predict()' which operate on time series. 4: Plot a time series When you plot a time series, the

Categories : R

Error while storing ggplots in list. Impossible to plot multiple ggplot, but possible to plot them seperately
Maybe you are looking for facet_wrap as Roland suggested. dat <- yourdata Get the mean and plot using facet_wrap moyparam<-ddply(dat, .(Date), function(x) data.frame(Mesure=mean(x$Mesure))) moyparam$Annee <- 1900 + as.POSIXlt(moyparam$Date)$year ggplot(moyparam, aes(Date, Mesure)) + geom_point() + theme_bw() + facet_wrap(~Annee, scales="free")

Categories : R

matlab color map nan in either matrix - 3 designated colors
Perhaps there are better solutions out there but I can come out with one here. Essentially, I'm creating an RGB representation of the image to show it. So I picked a colormap with the number of colors I wanted at first. Then, from the data, convert them to index and use in2rgb() to get the RGB image. Then, I can get the bin size of each color and label the color bar appropriately. % Randomly generate some data for demonstration A = [1 nan nan; 1 2 3; 4 5 6]; B = [nan 0 nan; 4 3 2; 1 2 1]; C = (A - B) ./ ((A + B) ./ 2); % Number of colors you want to use ncolor = 8; data_colormap = [jet(ncolor); 1 1 1; 0 0 0; 0.5 0.5 0.5]; data_range = [min(C(:)) max(C(:))]; data_ind = (C - data_range(1)) / (data_range(2) - data_range(1)) * (ncolor - 1) + 1; % Assign indices > ncolor for the special c

Categories : Matlab

How to display several binary images with different colors in matlab?
For 4 binary images, you have totally 2^4 = 16 possible "colors" per pixel according to it being "water"/"soil" or a combination of these classes (if it is possible in your system). Thus you can convert b1...b4 to a single image: >> l = b1 + 2*b2 + 4*b3 + 8*b4; >> imshow( l ); colormap( rand(16,3) ); % random color map

Categories : Matlab

Display range for RGB colors for imtool function in Matlab
Have you considered using imresize with nearest neighbour interpolation? I = imread('rice.png'); J = imresize(I, 2, 'nearest'); figure, imshow(I), figure, imshow(J) http://www.mathworks.com/help/images/ref/imresize.html

Categories : Matlab

How can I invert the colors of a picture, without changing the values in colorbar in Matlab
why wont you just invert the colormap by flipping up-down (flipud)? For example: cmap=flipud(colormap(gray)); colormap(cmap); or in a more compact way: imagesc(your_image); colormap(flipud(gray))

Categories : Image

How do I plot this? MATLAB
Based on the example on the kmeans documentation page I propose this "nested" logic: X = [randn(100,2)+ones(100,2);... randn(100,2)-ones(100,2)]; opts = statset('Display','final'); % This gives a random distribution of 0s and 1s in column 5: X(:,5) = round(rand(size(X,1),1)); [idx,ctrs] = kmeans(X,2,... 'Distance','city',... 'Replicates',5,... 'Options',opts); hold on plot(X(idx==1,1),X(idx==1,2),'rs','MarkerSize',12) plot(X(idx==2,1),X(idx==2,2),'r+','MarkerSize',12) % after plotting the results of kmeans, % plot new symbols with a different logic on top: plot(X(X(idx==1,5)==0,1),X(X(idx==1,5)==0,2),'bs','MarkerSize',12) plot(X(X(idx==1,5)==1,1),X(X(idx==1,5)==1,2),'gs','MarkerSize',12) plot(X(X(idx==2,5)==0,1),X(X

Categories : Matlab

How to make a semilog plot within a semilog plot in MATLAB?
Try using axes, for example: x = linspace(0,1); figure(1) % plot on large axes semilogy(x,1./x) % create smaller axes in top right, and plot on it axes('Position',[.55 .55 .33 .33]) box on loglog(x,exp(x))

Categories : Matlab

How should I autofit this Matlab plot?
I do not think that auto scale is the issue here, but rather the sequence of events. You try to "initialize" your plot in this line: graph = plot(y); However, in the previous line, you define y=zeros(size(1:rectN(end))); Therefore, the plot you see will be a straight line at y=0. The value of graph is the handle to the line object, in this case your line of y=0. After trying to set up the plot, you enter a loop and at each iteration, you add a value to your line handle (graph(i) = y(i)) - but you don't plot anything. If, after the loop, you look at the values of y or graph you see your new values - but they are never plotted. I doubt you need a loop in this case, maybe try this instead: I = 1:rectN(end); h = 2.*deltaF2.*(sin(I.*2.*pi.*deltaF2))./(2.*I.*pi.*deltaF2); w = 0.

Categories : Matlab

Matlab, scatter plot
The best way to compare two different groups is using analysis of variance. Analysis of variance (ANOVA) is a collection of statistical models used to analyze the differences between group means and their associated procedures (such as "variation" among and between groups). You should use ANOVA. also there are some functions included in MATLAB like: anova1, ... p = anova1(X,group) The standard ANOVA table divides the variability of the data into two parts: 1- Variability due to the differences among the column means (variability between groups) 2- Variability due to the differences between the data in each column and the column mean (variability within groups) Example 1 (from mathworks) Create X with columns that are constants plus random normal disturbances with mean zero and standa

Categories : Matlab

Need Help in Contour Plot in Matlab
There are a few things to note: 1.) As Jacob Robbins pointed out correctly in his comment, you should avoid using names from Matlab functions as variable names (in your case min and max). One very easy way to do this, is to use only upper case letters for variable names. 2.) You are correct in saying that your fis only one output (though one output in this case is not a single number, but a vector). That is, because you don't assign any indexing to it within the loop. 3.) Yes, both contour and surfc need at least 2x2 - because they plot information on a grid, which is itself at least 2x2 in nature. 4.) In your particular case, two loops may not be necessary. You seem to only be manipulating the x-vector and your grid is regular. Hence you might want to try this loop: for I=1:le

Categories : Algorithm

Matlab, plot with errorbars
Standard usage is errorbar(x,y,yerr, ...options...). In your case sounds like yerr = y.*percenterr/100

Categories : Matlab

Histogram plot in Matlab with constraints
I think this code based on your own will do it: data = rand(100,1); i = length(data); n = hist(data, i); min_number = 7; % minimum no. in each bin while any(n < min_number) i = i-1; [n bins] = hist(data,i); end figure bar(bins,n) (a). number of bin nbin = length(bins); (b). data in each bin if you mean the number of counts per bin, that is returned directly by hist as n of course if you mean, a pointer from each data entry to its corresponding bin, I would recommend modifying hist (make a copy as your own personal version) to return the output of histc which is run within hist, or calling histc after figuring out the edges of the histogram. (c). bin size for each bin hist uses equally sized bins, thus binsize = bins(2)-bins(1) (d). bin start & bin end for

Categories : Matlab

Matlab bar plot grouped but in different y scales
This uses the "plotyy(x1,y1,x2,y2,fun1,fun2)" variant of plotyy: %// Set these three variables as desired offset = (x(2)-x(1))/8; width = (x(2)-x(1))/4; colors = {'b','g'}; %// Do the plot plotyy(x-offset,y1,x+offset,y2, @(x,y) bar(x,y,width,colors{1}), @(x,y) bar(x,y,width,colors{2})); If you prefer x-ticks to appear only on used x values: h = plotyy(x-offset,y1,x+offset,y2, @(x,y) bar(x,y,width,colors{1}), @(x,y) bar(x,y,width,colors{2})); set(h,'xtick',x)

Categories : Matlab



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.