I'm trying to make points on a scatter plot clickable, they should link to another page. I will need to access the payload inside of each dot, so the onClick handler on is not enough as it only gives me the coordinates of the dot. I'd also like to be able to customize the dot color based on the payload.
I'd love to be able to create a custom dot component and pass it in as a prop, but I have not found a way to do that yet.
I am building a version of this parallel coordinate view in d3.js v4.
https://bl.ocks.org/syntagmatic/05a5b0897a48890133beb59c815bd953
In my example I have a predefined selection (in the form of a [min,max] array that I would like to set programatically as a brush in one or more of the axes, after the plot has loaded. But I cannot seem to find a way to do it. Most examples I found on setting a brush from code are using d3 v3 and use setting extent but that does not work anymore in v4 it seems.
can someone give me some tips and a simple example hot to do this in this case (so with multiple axes and brushes active) ?
thanks
Select your brush group and call brush.move, then also pass an array with the start and end coordinates. Your brush move event will then take care of the rest.
d3.select(".brush").call(brush.move, [[startX, endX], [startY, endY]]);
Within my current MATLAB GUI project, i have two axes objects. The first is used by the workaround "uibutton" (I don't use GUIDE) in order to display a LaTeX-formula (as far as I know, only axes labels are capable to use LaTeX whereas normal static text fields aren't...). The other axes object is used to actually plot a 3D-function.
The program has the following steps:
the first axes creats the LATEX-formula (e.g. f(x)=).
User enters a function in the edit field after the LaTeX-formula (e.g. f(x)=a+b).
User presses a "plot"-button.
3D-function is plotted in the second axes object.
Problem:
As soon as the 3D-function is plotted, the nicely rendered LaTeX-formular becomes crisp. Is there any way to prevent this from happening?
http://i42.tinypic.com/348pq2u.png (See picture for problem demonstration)
Check your figure properties before and after you draw the 3D plot
get(gcf, 'renderer')
My guess is that plotting the 3D function changes the renderer from the default ("painters") to another (likely OpenGL). Matlab's Latex rendering does not seem to play well with zbuffer or OpenGL (these produce bitmaps rather than line art).
You may be stuck if painters can't render your 3D graphics properly, but you can try to force it by setting the renderer manually back to painters
set(gcf, 'renderer', 'painters')
I have a canvas , which have rectangles dynamically created in the code . (Around more then 100 rectangles .) I would like to have the event handling created for all the recatngles .
Instead of creating different event handling functions , I would like to have one event handling function and then , based on the rectangel which is clicked , handle the event correspondingly . I am new to this windows development .
Please share some light on this .
Thanks-Best Regards,
Yash
There's no built in way to do this. I've made a few tutorials to help people get started.
Let me just say that this would be easier to do in SVG if that's all you need.
In canvas there is no way to handle individually created elements inside the canvas. You can implement it programmatically. If they are just plain rectangles then may be divs are better alternative. If they can be any drawing you need to capture the mouse move events on the canvas. Find the location of mouse move event and use a formula to find if the mouse is inside any drawing or not. I have implemented same thing for polygonic shapes. All I do is that find the mouse coordinated and then check if the coordinate lies inside any shape.
Edited for clarity:
I have a GUI that controls a script that generates approximately 40 plots. I want to display any given plot in the GUI window on demand by selecting its number in a drop-down box. The problem is that the plots take a while to generate so I would rather make them once and then load them as needed into the axes object in the GUI. The plots each have different properties, labels, legends, etc..
I tried generating figures and then saving them and trying to load that into the axes object in the GUI and it did not work.
If I initially make the plots using the axes object in the GUI as the target axes I can't save the plot and the legends, etc..
Is this possible in MATLAB?
If I understand the question correctly, you have a GUI with axes and a callback to plot stuff into the axes. For some reason, e.g. because plotting takes a while, you want to be able to save a specific plot and have the ability to reload it.
The easiest way to deal with this issue is to not put an axes object into your GUI, but to use a two-window GUI, where one window has all the controls, and the other is the figure into which you plot stuff. This is advantageous for several reasons: Saving/loading becomes easy, you have access to the figure toolbar, and you can resize etc the figure as you wish (resizing GUIs is generally hairy). You can store the handle to the axes of the figure in the GUI handle structure via SETAPPDATA and access it via GETAPPDATA. Note that you'll want to put a small check at the beginning of your plotting callback, where you check whether the figure still exists using ISHANDLE on the axes handle, and open a new figure if the check returns false.
If you really want to have an axes object in your GUI, the easiest is to just save the x and y data, as well as other properties of the plot that a user may be able to customize (whether the legend is on, or off, or the legend's position property), so that you can regenerate it on the fly.
If, for some reason it is not sufficient to save just properties, you can generate a hidden figure, and use COPYOBJ to copy the axes and its children to that figure, which you then save. However, this is rather clumsy and might come with all kinds of surprising annoyances.
You need to know the handles of axes within the figure. Otherwise it will be difficult to change the axes properties if the figure contains a newer axes object, because gca will refer to the new axes.
The axes can be accessed post figure generation through the figure object because individual axes of a figure are children of the figure object. The following code snippet may help you.
close all
subplot(2,1,1)
subplot(2,1,2)
hAxes = get(gcf, 'Children')
get(hAxes(1)) %shows axes properties of one axes obj
get(hAxes(2)) %shows axes properties of the other
set(hAxes(1), 'YTickLabel', ['a';'b';'c';'d';'e';'f']) %set an axis property
I'm guessing a bit here, but it sounds like you want to create a GUI with an axes that displays different plots, legends, etc. based on which item of a drop-down menu is selected. If this is right, I'm guessing the problem you are having is that plotting a new set of data in the axes causes the old data to be replaced, leaving you to have to regenerate the entire plot anew every time you select a new menu item.
One way I would consider approaching this problem would be to make use of UIPANELs and the 'Visible' property of graphics objects. You could create one panel per menu item, add an axes to each along with whatever data you wish to plot, then simply toggle the visibility of the panels using the SET command instead of replotting everything when a new menu item is selected. Here's an example:
hFigure = figure; %# Create a figure
hPanelA = uipanel('Parent',hFigure); %# Add panel A to the figure
hAxesA = axes('Parent',hPanelA); %# Add an axes to panel A
plot(hAxesA,1:10,rand(1,10),'r'); %# Plot a red line
text(5,0.5,'hello','Parent',hAxesA); %# Plot some text
legend(hAxesA,'red line'); %# Add a legend
hPanelB = uipanel('Parent',hFigure); %# Add panel B to the figure
hAxesB = axes('Parent',hPanelB); %# Add an axes to panel B
plot(hAxesB,1:10,rand(1,10),'b'); %# Plot a blue line
text(5,0.5,'world','Parent',hAxesB); %# Plot some text
legend(hAxesB,'blue line'); %# Add a legend
Now, you can make panel A visible and panel B invisible by doing the following:
set([hPanelA hPanelB],{'Visible'},{'on'; 'off'});
And you can do the reverse (hide panel A and show panel B) by doing this:
set([hPanelA hPanelB],{'Visible'},{'off'; 'on'});
You should notice that toggling between the two panels with their two separate axes is quick and smooth, which likely wouldn't be the case if you had to erase and replot data in a single set of axes every time you wanted to look at a new plot. Creating all the graphics objects you need when the GUI is created, then modifying the visibility (or other properties) as needed with the SET command makes for a more efficient GUI.
Also note that you can still modify object properties even when they are invisible, so (continuing from my example above) I could do something like this:
set([hPanelA hPanelB],{'Visible'},{'on'; 'off'}); %# Hide panel B
set(hPanelB,'BackgroundColor','b'); %# Change the color of panel B
set([hPanelA hPanelB],{'Visible'},{'off'; 'on'}); %# Show panel B
And now you should see that the background color of panel B is blue. If you also saved handles to your plotted lines and text, you could update them with new values before making them visible again.