Scilab 3d Plot Datatips - scatter-plot

I am plotting some data in Scilab as 3d-Scatter plot (Scilab 6).
With the datatip toggle it is able to show some information about each data point: x,y,z value.
I am actually plotting node-values, x,y are the coordinates, z is the damage.
Is it possible to change the output of the datatip? I would like to display a node-label instead of the coordinates using the datatip-function!
Thank you!

Use datatipSetDisplay (cf. examples in help page)

You can set a custom diplay function per "PolyLine" object in your plot, e.g.
t=0:0.1:10;y=sin(t);
function s=mydatatip(h),s="DATATIP",end
plot(t,y)
datatipSetDisplay(gca().children(1).children(1),mydatatip)
Please note, here gca().children(1).children(1) is a handle to the "PolyLine" object of the plot.

Related

Is it possible to plot a figure with arrows as shown in image attached in MATLAB?

Can I draw such a plot in Matlab? If not what would be the right software to draw it? Later, I need to paste figure in MS word file.
Sure, you need the annotation function, e.g.
figure('Color','w');
plot(-pi:0.01:pi,sin(-pi:0.01:pi));
ax=gca();
set(ax,'YAxisLocation','left','XAxisLocation','bottom','Box','off','XTick',[],'YTick',[])
annotation('textarrow',[0.4,0.5],[0.4,0.5],'String','P')
annotation('arrow',[ax.Position(1),sum(ax.Position([1,3]))],ax.Position([2,2]),'LineWidth',0.5);
annotation('arrow',ax.Position([1,1]),[ax.Position(2),sum(ax.Position([2,4]))],'LineWidth',0.5);
annotation('textbox',[ax.Position(1)-0.05,sum(ax.Position([2,4]))-0.05,0.05,0.05],'String','Q','EdgeColor','none')
annotation('textbox',[sum(ax.Position([1,3]))-0.05,ax.Position(2)-0.05,0.05,0.05],'String','R','EdgeColor','none')

how to create map from given coordinates in d3js

So I need to create the map of my country from the coordinates I have so that I can plot some xyz data on it.
I was able to plot the map with the help of Mike Bostock tut http://bost.ocks.org/mike/map/
But when I went through the .json file, the coordinates mentioned are totally different from the coordinates I have. Like Patna(India) has [5812,6567] as coordinates in the json file while actual coordinates are [25,85].
Could anybody guide me how can I use the coordinates with me to plot the map and then display some data on it??
EDIT:
With the help from #user1614080, I was able to understand how coordinates are converted into screen coordinates.
The issue I have is: I want the map of India in a certain way. For that purpose, I would like to use the list of latitude & longitude I have. But I dont know how to convert these lat-longs into topojson/geojson format.
For the time being I did a simple line plot with the lat-long I had. Some of the values from the coordinates.csv I used for the line plot are:
Longitude,Latitude
88.75,21.58
88.33,21.50
88.17,22.08
88.00,21.75
87.58,21.58
87.08,21.42
But I would like to use topojson/geojson for the same. how can I convert the data from "coordinates.csv" into json?

mapped imshow does not work in subplot if different palette

I found that apparently, a mapped version of imshow function does not work in subplot. Is this by design?
The following script
rgb=imread('../FruitSample_small.png');
[ind,map]=rgb2ind(rgb,4);
figure
imshow(ind,map)
figure
subplot(5,1,1);
imshow(ind,map)
subplot(5,1,2);
imshow(ind==0)
subplot(5,1,3);
imshow(ind==1)
subplot(5,1,4);
imshow(ind==2)
subplot(5,1,5);
imshow(ind==3)
produces the following result
i.e. mapped version looks black. If I plot mapped version only (5 times) it looks ok. I.e. subsequent plotting apparently change the palette.
How to plot all these 5 images on same figure then?
Colormap is a property of the figure, not the axis. The second call to imshow resets the Colormap for the entire figure. Here is some more information and a Matlab file exchange solution to the problem. If you download the function described in that link, freezeColors, you can use it in your code like this.
rgb=imread('peppers.png'); % example image included in matlab
[ind,map]=rgb2ind(rgb,4);
figure
imshow(ind,map)
figure
subplot(5,1,1);
imshow(ind,map)
freezeColors % keep colors the same after other subplots are displayed
subplot(5,1,2);
imshow(ind==0)
freezeColors
subplot(5,1,3);
imshow(ind==1)
subplot(5,1,4);
imshow(ind==2)
subplot(5,1,5);
imshow(ind==3)
And the resulting second figure will look like this:

Plot time series and image in R so that x axis labels line up perfectly

I am trying to plot a time series (a seismograph) with a corresponding spectrogram in R.
Since I would like to compare the time series with the spectrogram, the X axis labels on the time series need to line up with the X axis labels on the spectrogram. However, I'm having a lot of trouble with this. The best I've been able to do so far is use
par(mar=c(0,10,0,8))
and try to manually force the spectrogram labels to line up with the time series labels by tweaking the spectrogram margin. Of course this is only approximate and they still do not line up perfectly. Is there a way to make the axes generated by the code below match up with each other?
par(mfcol=c(2,1))
plot(seq_len(1000)*0.01, sin(2*pi*seq_len(1000)*0.01), type="l",xlab="Time",
ylab="Amplitude", main="Time Series", xlim=c(1,10))
image(seq_len(1000)*0.01,seq_len(100)*0.1,array(runif(1000000),dim=c(1000,100)),
xlab="Time", ylab="Frequency", main="Spectrogram", xlim=c(1,10))
Thanks in advance!
This seems to work:
par(mfcol=c(2,1))
plot(seq_len(1000)*0.01, sin(2*pi*seq_len(1000)*0.01), type="l", xaxs="i")
image(seq_len(1000)*0.01,seq_len(100)*0.1,array(runif(1000000),dim=c(1000,100)),
xlab="Time", ylab="Frequency", main="Spectrogram")
Just drop the xlim= arguments and use xaxs="i" in the plot() function to match the default for image().
You can either add xaxs='i' to the call to plot (this removes the extra padding so it lines up with the image plot), or you could use par('usr') after the 1st plot to see what the x limits are and use those values in the xlim call in image.
It turns out that this is way easier than it looked initially. The secret is to make a "dummy plot" and then add the image to the plot. So here's how the new, working code looks:
par(mfcol=c(2,1))
plot(seq_len(1000)*0.01, sin(2*pi*seq_len(1000)*0.01),
type="l",xlab="Time",ylab="Amplitude", main="Time Series")
plot(c(0,10), c(0,10), type="n") #Dummy plot with axis limits for our spectrogram
image(seq_len(1000)*0.01,seq_len(100)*0.1,array(runif(1000000),dim=c(1000,100)),
xlab="Time", ylab="Frequency", main="Spectrogram",add=TRUE)
Similar, but conversely, to Greg Snow's answer, you could add xaxs='r' to the call to image as follows:
par(mar=c(0,10,0,8))
par(mfcol=c(2,1))
plot(seq_len(1000)*0.01, sin(2*pi*seq_len(1000)*0.01), type="l",xlab="Time",
ylab="Amplitude", main="Time Series", xlim=c(1,10))
image(seq_len(1000)*0.01,seq_len(100)*0.1,array(runif(1000000),dim=c(1000,100)),
xlab="Time", ylab="Frequency", main="Spectrogram", xlim=c(1,10), xaxs="r")
Don't forget to save your par() setting first.
(maybe I should have put that above)

Matlab Image Processing

I'm facing a problem when displaying an image and using hold on to then plot hough lines on top of it. I want to store this image in a variable including lines on it and use it further. How can I do that?
You can use the copyobj for this. Or the getframe function if you're making a movie.

Resources