How to change efficiently Colormap of big .fig files in Matlab? - matlab

I have some 2 GB .fig files where I would like to change colormaps smartly.
The initial colormap is colormap(1-gray(1024)); made initially for computers.
I would like to change smoothly to Parula etc for visualization purposes.
There is a need for changing to many different colormaps efficiently.
It may be the case that the original gray is not the optimum for the starting point.
My main interest is the time-series analysis with Mathematica where I need to find some colormap which I can use with meshgrid data structure.
There are some colormaps presented in the book Passive Acoustic Monitoring of Cetaceans by Walter M.X. Zimmer which seem to be relevant here. Some alternatives to be considered
colormap(1-gray(1024))
colormap(1-gray(12))
colormap(1-gray)
colormap(cmap)
colormap(1-gray(7*2))
colormap(1-gray(8*2))
The situation is that changing from one colormap to another is too slow with big .fig files. Little (or no?) history is taken into account when changing the colormap, I think. The previous change of a colormap does not decrease the execution time of the next colormap; although you would change subsequently back to the initial colormap. The biggest problem is with colormaps that are not injective with each other.
Questions
Why do they take everything except clauses (1-gray)?
How can you change smoothly colormap of big .fig files in Matlab? There are similarities between some colormaps. Sometimes, the default way etc colormap(parula(200)) is too slow. I would like to speed up things if similarities between colormaps could be used; by configuring the initial colormap suitable for some changes of colormaps.
How can you decide a colormap such that it is usable for the time-series analysis in Mathematica? Just an example, please.

Use Mathematica 11 instead, since its default colormap has much better contrast and its viewer fits much better for your dynamic target.

Related

Matlab, high quality plot, two legends

I would like to produce a plot with two y-axis and two legends, looking something like this:
I have modified a code I found online to produce a high-quality plot to use in reports/papers. I was wondering how you add a second y-axis in such a code? I have attached the matrix and code to produce the high-quality plot: https://drive.google.com/file/d/1aKZLFeoO1wmQ1P2tEiiucvOFI7PehkGL/view?usp=sharing
https://drive.google.com/file/d/1aKZLFeoO1wmQ1P2tEiiucvOFI7PehkGL/view?usp=sharing
NOTE: This is basically a comment, however, it grew too long, and I felt it was too important not to mention properly.
Reporting plots from Matlab should always, unless you have some very good excuse, be done using vector graphics, i.e. pdf, ps, eps or similar format. The reason for this is the quality, e.g. here I have taken your high-quality and the similar pdf-version and zoomed in.
The png version has artifacts. The reason for this is that the png (similar for jpg and more) is that the picture is saved using pixels, thus when you zoom the quality deteriorate.
The pdf version, which is made with vector graphics, save the vectors, thus when I zoom the pdf viewer can regenerate the pixels and maintain the same quality. As an added bonus, the vector-graphic version is typically smaller in size.
This is made in Matlab using
saveas(gcf,'myfigure.pdf')
Use yyaxis to add another plot with an axis. Take a look at the following modified portion of your code.
yyaxis left
plot(N(:,1),N(:,3)/(27.5*2),'b-','DisplayName','Location','LineWidth',lw); %<- Specify plot properites
yyaxis right
plot(N(:,1),N(:,4)/(27.5*2),'r-', 'DisplayName','NorthEast','LineWidth',lw); %<- Specify plot properites
legend('Location', 'NorthEast');

Linking plotted data with color and size sources in MATLAB

This question is related to the question posted here, in which I outline a problem I'm facing regarding rapid visualization of 3D scatter plotted data in MATLAB during a simulation. (Sample code and data are also provided there.)
As an alternative to setting the XData, YData, ZData, SizeData, and CData properties of a 3D scatter plot in MATLAB, I'm wondering if it's possible to have all of their corresponding sources be dynamically linked to points that are 3D scatter plotted. The linked values would be queued into a buffer and plotted periodically (say, every 0.5 s). From what I understand, the sources are refreshed in the background, so plots with linked data would not slow down the simulation. From what I see in the documentation, only XDataSource, YDataSource, and ZDataSource are specified. Is dynamically linking the size and color data sources also possible, and if not, is there a simple workaround?
As a reminder, I'm using MATLAB R2016a on Windows 7.
Is dynamically linking the size and color data sources also possible, and if not, is there a simple workaround?
Yes, it is possible using the similarly named properties
SizeDataSource
CDataSource
These properties are set to the string names of the variables you want linked for updating. Then, with linking on, subsequent updates to these named variables will be reflected in your plots ever 1/2 second or so (at the fastest).
But, there is a big caveat here with your specific example.
The xxxxSource fields are typically initialized at the outset, when a graphic handle is created. This would be in your initial scatter3 calls.
The issue is that you have eight separate scatter plot handles, each referencing the same variable(s), but with different indexes. That is, you are updating the indices into these variables to produce your images.
A brute force way to use parameter linking here would be to create eight different variable names and link each to its corresponding scatter plot handle.
I think the cleaner solution is to use a timer callback to update things on a set time interval.

Matlab: How to avoid artefacts in filled contour plots

I am trying to export filled contour plots from Matlab as vector graphics to include in a Latex file. My current methodology is:
contourf(x,y,v_mag,20), axis([0,width,0,height]),daspect('manual') ;
grid off
colormap jet
h = colorbar;
caxis([0 v_lid])
h.Label.String = 'Velocity Magnitude (m/s)';
set(gcf,'renderer','painters')
export_fig('-painters', '-transparent', 'pdf', 'filename.pdf');
The problem with this method is that it produces artefacts (the white lines) which look like the following:
I understand that these white lines are the polygons defining the shaded areas which have invisible edges, and don't quite overlap (according to here). The problem is caused by the pdf viewer itself which tries to smooth the lines displayed on the screen (according to here). My problem is that most people viewing the document will not know this and will not know how to prevent the viewer doing this. So my questions is:
Is it possible to create a vector graphic of a filled contour plot from Matlab without these artefacts?
Eps produces the same problems. I have tried to use the SVG function but have not had any luck. I am trying to avoid using raster graphics due to the pixelation caused by zooming in. Any advice would be much appreciated.
EDIT - Additional info - Using Matlab v.2014b and Ghostscript v.9.15
This is an extremely frustrating issue for which there seems to be no solution (or even, few attempts at a solution), and it has been many years now. In summary, Matlab cannot cope with outputting artefact-free contour or surface plots (anything with complicated meshes or transparencies).
I can suggest a simple workaround that will work in most cases, where the colours or details of the underlying contour plot do not need to be preserved perfectly.
Output a version of the figure without lines in png format with high enough resolution.
Output a version of the figure without colours in pdf format. This should be free of any artefacts. If your figure it complicated and has many transparencies, you may need to output multiple versions building up the 'levels'.
Use Adobe Illustrator (or some equivalent) to perform a vectorized trace of the raster image. You may lose some detail here, but for simple contour plots with limited details, it will be converted easily to vectorized form.
Overlay the two images within Illustrator. Output in vector format.
This also allows you to use things like Illustrator's ability to compress pdfs.
If you don't want to toy with vectorizing the raster output, you can also simply replace steps 3-4 and combine a raster colour image with a vectorized line image. This would work well for complicated contour plots giving you crisp lines, but the ability to compress the underlying colours.
Eventually, MatLab 2013b doesn't have this problem. Furthermore the files it produces has much less volume. That is because MatLab 2013b composes vectorized image of big overlapping figures, while MatLab 2014b makes that awful meshing.
Here the first file was got with 2013b and the second with MatLab 2014b (I highlighted one of the polygons with red stroke to show the difference). The volumes differ in approximately 22 times (38 Kb vs. 844 Kb).
So it is not the viewer problem, it's how the image is exported from MatLab.
The issue is also discussed here Triangular split patches with painters renderer in MATLAB 2014b and above, but still no direct solution.

Reproduce a colorbar with auto-rescaling between min & max value to use entire spectrum

I am new to matlab and stackexchange too.
I wish to reproduce a colorbar for my own work (guess it was made using tecplot) preferably in MATLAB or python (matplotlib).
Here's an example of what I want to reproduce:
http://iopscience.iop.org/0963-0252/23/1/015007/downloadHRFigure/figure/psst484284fig14
My idea is to have a script which can be run on any x-y-z type of data such that this colorbar is applied in a way that all the colors are used (presume it will be some kind of rescaling?)
This colorbar does not need to display the actual values but just min and max will suffice.
Many thanks for all your help and suggestions.
This answer is for matlab. Since you do not say anything about recreating the colormap I assume that you know how to do that. However, if not, try the colormap editor.
surf(peaks(30));
colormapeditor;
Where peaks is a function creating some good demo data. The colormap can the be obtained from the figure. About your problem: Normally the colormap is automatically scaled to use the full spectrum of your colormap. If this for some reason does not work, set the CLim property to the range of your spectrum. That can for example be the maximum and minimum for your data or some other suitable range.
Good luck!

5-dimensional plotting in matlab for classification

I want to create a 5 dimensional plotting in matlab. I have two files in my workspace. one is data(150*4). In this file, I have 150 data and each has 4 features. Since I want to classify them, I have another file called "labels" (150*1) that includes a label for each data in data files. In other words the label are the class of data and I have 3 class: 1,2,3
I want to plot this classification, but i can't...
Naris
You need to think about what kind of plot you want to see. 5 dimensions are difficult to visualize, unless of course, your hyper-dimensional monitor is working. Mine never came back from the repair shop. (That should teach me for sending it out.)
Seriously, 5 dimensional data really can be difficult to visualize. The usual solution is to plot points in a 2-d space (the screen coordinates of a figure, for example. This is what plot essentially does.) Then use various attributes of the points plotted to show the other three dimensions. This is what Chernoff faces do for you. If you have the stats toolbox, then it looks like glyphplot will help you out. Or you can plot in 3-d, then use two attributes to show the other two dimensions.
Another idea is to plot points in 2-d to show two of the dimensions, then use color to indicate the other three dimensions. Thus, the RGB assigned to that marker will be defined by the other three dimensions. Of course, that means you must be able to visualize what the RGB coordinates of a color represent, so you need to understand color as it is represented in an RGB space.
You can use scatter3 to plot your data, using three features of data as dimensions, the fourth as color, and the class as different markers
figure,hold on
markerList = 'o*+';
for iClass = 1:nClasses
classIdx = dataClass==iClass;
scatter3(data(classIdx,1),data(classIdx,2),data(classIdx,3),[],data(classIdx,4),...
'marker',markerList(iClass));
end
When you use color to represent one of the features, I suggest to use a good colormap, such as pmkmp from the Matlab File Exchange instead of the default jet.
Alternatively, you can use e.g. mdscale to transform your higher-dimensional data to 2D for standard plotting.
There's a model called SOM (Self-organizing Maps) which builds a 2-D image of a multidimensional space.