I am currently trying to draw an oscillation using Octave. This is what I want to achieve in the end:
In this diagram, the y axis arrow is drawn in the middle of the graph instead of at the top or bottom.
I think this way it makes a lot of sense because the arrow kind of mirrors the graph itself periodically.
Now, what I have so far:
x = [0:.1:10];
plot(x, sin(x);
box off
Which looks like this:
But I can't get the y axis arrow to be in the middle. So far I've read
The axis documentation
The page about two-dimensional plots
But I can't find anything about positioning the axis. Thanks for any help in advance.
Using your example:
x = [0:.1:10];
plot(x, sin(x));
box off
set( gca, 'xaxislocation', 'origin' )
Some more, possibly helpful tips:
In general, if you don't know what parameters are available in a graphical object handle, and you want to "check", you can use get with an empty string, e.g. get( gca, '' ) to check all the parameters that you can 'get' or 'set' on the current axes object.
Similarly, if you want to check what values a particular parameter can be set to, you can do, e.g. set( gca, 'xaxislocation' ), i.e. without providing the value to set it to. If that particular parameter only accepts values from a specific set of values (instead of e.g. a numerical array), then Octave will then show you what these options are (and also which is the default).
Obviously, if you know what you're looking for, you can also just go straight to the relevant page in the octave manual and search the page for it :)
Since the online manual is quite large, and has no 'search' facility of its own (it does within octave, but the online version doesn't), in order to jump straight to the relevant section I often find it useful to do a duckduckgo (or google) site-specific search, e.g. "xaxislocation site:https://octave.org/doc/v6.2.0/"
Related
I am using the Edit2D extension on an svf created from a 2D dwg file and have a question about transforms. The Autodesk.Edit2D.Polygon's that are created have a getArea() method which is great. However it's not in the correct unit scale. I tested one and something that should be roughly 230sf in size is coming back as about 2.8.
I notice that the method takes an argument of type Autodesk.Edit2D.MeasureTransform which I'm sure is what I need, however I don't know how to get that transform. I see that I can get viewer.model.getData().viewports[1].transform. However, that is just an array of 16 numbers and not a transform object so it creates an error when I try to pass it in.
I have not been able to find any documentation on this. Can someone tell me what units this is coming back in and/or how to convert to the same units as the underlying dwg file?
Related question, how do I tell what units the underlying DWG is in?
EDIT
To add to this, I tried to get all polylines in the drawing which have an area property. In this case I was able to figure out that the polyline in the underlying dwg was reporting its area in square inches (not sure if that's always the case). I generated Edit2D polygons based on the polylines so it basically just drew over them.
I then compared the area property from the polyline to the result of getArea() on the polygon to find the ratio. In this case it was always about 83 or 84 times smaller than the square foot value of the polyline it came from (there is some degree of error in my tracing system so I don't expect they would be exact at this point). However, that doesn't fit any unit value that I know of. So remaining questions:
What unit is this?
Is this consistent or do I need to look somewhere else for this scale?
Maybe you missed the section 3.2 Units for Areas and Lengths of https://forge.autodesk.com/en/docs/viewer/v7/developers_guide/advanced_options/edit2d-use/
If you use Edit2D without the MeasureExtension, it will display all coordinates in model units. You can customize units by modifying or replacing DefaultUnitHandler. More information is available in the Customize Edit2D tutorial.
and https://forge.autodesk.com/en/docs/viewer/v7/developers_guide/advanced_options/edit2d-customize/
BTW, we can get the DefaultUnitHandler by edit2dExt.defaultContext.unitHandler
Ok after a great deal of experimentation and frustration I think I have it working. I ended up looking direction into the js for the getArea() method in dev tools. Searching through the script, I found a class called DefaultMeasureTransform that inherits from MeasureTransform and takes a viewer argument. I was able to construct that and then pass it in as an argument to getArea():
const transform = new Autodesk.Edit2D.DefaultMeasureTransform(viewer);
const area = polygon.getArea(transform);
Now the area variable matches the units in the original cad file (within acceptable rounding error anyway, it's like .05 square inches off).
Would be nice to have better documentation on the coordinate systems, am I missing it somewhere? Either way this is working so hopefully it helps someone else.
I am working on a data analysis project in R. In the end I need to hand in an HTML document.
I created a couple of PCA biplots using the autoplot funciton, about like this:
autoplot(pca, data = expression, x = 1, y = 2)
#pca is a prcomp element and expression is a data frame
By now, they are plotted one below the other in the HTML document. Is there a function that allows me to click through the different plots? So that only the first plot is shown and by clicking on an arrow or something, the second plot is shown in the same place? Kind of like a gallery.
The way multiple plots from the same chunk are show in an R Markdown would be even better, so you can select one specific plot by clicking on a miniature version of it
I've been looking through the internet a lot and hoped to find something from the html widgets page, but couldn't find anything after all.
I would really appreciate your help on this. Thanks :)
EDIT: I am not sure whether I am allowed to hand in a shiny applet, so being able to do it solely in the HTML would be awesome
Right, I found a way to do it that works fine for me. I used the {.tabset} argument I found at this link:
https://bookdown.org/yihui/rmarkdown-cookbook/html-tabs.html
## Results {.tabset}
### PC1-PC2 biplot
autoplot(pca, data = expression, x = 1, y = 2)
### PC1-PC3 biplot
autoplot(pca, data = expression, x = 1, y = 3)
## {-}
To use this, you have to create headers in your markdown using the # symbol. All headers that are one "level" below the one to which you added the {.tabset} argument (i.e. that have one more # symbol) will be the names of your tabs.
To close the tab section, you use the same number of # symbols you used in the header behind which you wrote the {.tabset} argument and write {-}.
Situation: Trying to output and also manipulate an indexed image.
Problem: When using ind2rgb(image, colormap(x)), we received an error saying that the indexed image contains colors outside of colormap, where x is the colormap option.
Question: How to work around this?
Additional information: I used imshow(image, colormap(x)), where I used every colormap available on Octave in substitution of x.
I believe this happens because you have more indexes than colors in colormap. Just make a bigger colormap. You can do that with the sysntax colormap(x(size_of_cmap))
ind2rgb(image, colormap(viridis(max(image(:))))
Alternatively, create the colormap and interpolate it. Caution: this can create artifacts in the color due to HSVs circular behavior.
m=max(image(:));
cm=colormap(x);
hsv=rgb2hsv(cm);
cm=interp1(linspace(0,1,size(cm,1)),hsv,linspace(0,1,m));
cm=hsv2rgb(cm);
ind2rgb(image,cm);
I suggest using the first solution if possible.
I'm writing a program for a college course. I import a .PPM file saved as a 2-d array from main into the function. Then I have to update the pixels of a graphics window (which is opened in main) using .setPixel and color_RGB() method and functions.
The pixels are updating, however there is a white pixel in between each colored pixel for some reason. It's not the PPM file (they were supplied by my professor and I've tried multiple ones), so it has to be my function.
Warning: I am not allowed to use anything in my program that we have not yet covered in our course (it's a first year, 4 month course so the scope is not massive). I don't need to know exactly HOW to fix it, as much as I need to know why it's doing it (AKA: I need to be able to explain how I fixed it, and why it was breaking in the first place).
Here is my function:
def Draw_Pic(pic,pic_array, sizeX, sizeY, gfx_window):
for y in range(sizeY):
for x in range(0, sizeX, 3):
pixel_color = color_rgb(pic_array[y][x],pic_array[y][x+1],pic_array[y][x+2])
pic.setPixel(x,y,pixel_color)
gfx_window.update()
You are using range(0, sizeX, 3) which creates a list with values 0 to sizeX with increment 3.
So your x goes 0..3..6..9 etc. Makes perfect sense for the part where you assemble pixel color from 3 components, but then you do pic.setPixel(x,y,colors) using the same interleaved x.
Hope that helped.
P.S. By the way, why "colors" and not "color"?
edit Also, that way you'll copy only 1/3 of the image in pic_array.
I wonder if you could/would help me.
I have a page (java script/ html5/webgl)
and I am displaying a set of points,
then when the user pressess on a point I would lik to find the x and y coordinates that I set in the first place.(range of 0 to 1)
what I get from the even is the x and y screen coordinates (pixals)
from even.offsetX and so.
what is the right math to get to the acsual points?
please help
In regular OpenGL, the command you need is gluUnProject:
http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml
For WebGL, you will have to roll your own since it doesn't have any fixed function pipeline support. Assuming that you are using standard transformation matrices, you can just modify the formulas in that man page. It would be hard to say anything more specific without the details of you set up your coordinate systems.