Currently, I use MATLAB extensively for analyzing experimental scientific data (mostly time traces and images). However, again and again I keep running into fundamental problems with the MATLAB language and I would like to make the switch to python. One feature of matlab is holding me back however: its ability to add datatips to plots and images.
For a line plot the datatip is a window next to one of the data points that shows its coordinates. This is very useful to quickly see where datapoints are and what their value is. Of course this can also be done by inspecting the vectors that were used to plot the line, but that is slightly more cumbersome and becomes a headache when trying to analyze loads of data. E.g. let's say we quickly want to know for what value of x, y=0.6. Moving the datatip around will give a rough estimate very quickly.
For images, the datatip shows the x and y coordinates, but also the greyscale value (called index by MATLAB) and the RGB color. I'm mainly interested in the greyscale value here. Suppose we want to know the coordinates of the bottom tip of the pupil of the cat's eye. A datatip allows to simply click that point and copy the coordinates (either manually or programmatically). Alternatively, one would have to write some image processing script to find this pixel location. For a one time analysis that is not worthwhile.
The plotting library for python that I'm most familiar with and that is commonly called the most flexible is matplotlib. An old stock overflow question seems to indicate that this can be done using mpldatacursor and another module seems to be mplcursors. These libraries do not seem to be compatible with Spyder, however, limiting their usability. Also, I imagine many python programmers would be using a feature like datatips, so it seems odd to have to rely on a 3rd party module.
Now on to the actual question: Is there any module (or simple piece of code that I could put in my personal library) to get the equivalent of MATLAB's datatips in all figures generated by a python script?
Related
I have some time series plots I've done a long time ago that I would like to improve in terms of graphics and style. However, I didn't save the raw data and I cannot recover them.
So I was wondering, is there a way to retrieve data points from a chart image (e.g. png file)? like I input an image and I get a csv/dataframe/array with pairs of x,y coordinates?
To give an idea, that's the kind of images I would like to convert:
I've seen this GRABIT could potentially work but I'm not familiar with MatLab. Is there anything python-based or possibly some web tools?
Preferences:
work on linux systems (in particular ubuntu)
doesn't require installation
there is a little and simple software develop here in Brazil that can do this kind of thing.
You have to download in the following link:
http://paginapessoal.utfpr.edu.br/lasouza/analise-nao-linear-de-estruturas/Pega%20Ponto%201.0.exe/view
You can load the image, specify the origin and set the x and y labels. After you can retrieve the points that you clicked on the image.
I have many stl CAD files for 3D printing and I was wondering how I can manipulate an individual CAD file by making a simple change programatically. Like if I want to double the dimensions of everything in the CAD file, how could I accomplish this in python? I could convert it to gcode if that makes things simpler.
I have come across FreeCad but I am not sure if this is the easiest and best way of programmatically altering CAD files. I also wanted an option that allows for freedom of manipulation beyond just size, maybe also seeing how I can programmatically alter the shape of the CAD file.
Well to be precise, STL files are even not meshes, but triangles soups. Which means that triangles are even not connected to each other (well they need to be adjacent to be used by software generatif g-code, but no obligation else)
just for clarification: g-code format is just a sequence of instructions for the machines (3d-printers, etc) so it's very good for printers, but also certainly the worst format to manipulate geometry.
one solution
you can use the python pymadcad module to deal with STL files
So for simple transformation operations (such as scale, translation etc)
from madcad import *
part = read('path/to/your_file.stl')
transformed = part.transform(mat3(2)) # scale by a factor 2 (diagonal matrix of 2)
write(transformed, 'path/to/output_file.stl')
If you need more complex operations (such as booleans, chamfers, etc) you will need to make the triangle connected again before the desired operations.
from madcad import *
part = read('path/to/your_file.stl')
part.mergeclose() # merge points at the same location
# your desired operations (example)
transformed = union(part, icosphere(vec3(1,1,1), 3.)) # add a sphere a diameter 3
write(transformed, 'path/to/output_file.stl')
note
pymadcad is internally using numpy-stl to import stl files, if you need only basic manipulations you can also only install that one
STL files are meshes. Their exterior is defined by triangulated surfaces. Meshes are notoriously difficult to modify after the fact. That's why you always want to save your designs in the native format and also in an open solid format like .STP or .IGES.
That said, simple scaling of a mesh is pretty easy and can be done trivially in FreeCAD.
You can do it in the gui in the mesh design workbench or through python. Here's a post about that:
https://forum.freecadweb.org/viewtopic.php?t=9109#p74047
FreeCAD also has some tools to convert a mesh into a solid. Results are usually less than spectacular but might be good enough depending on your needs. Search on the FreeCAD forum for posts about converting or look here: https://wiki.freecadweb.org/FreeCAD_and_Mesh_Import
Gcode doesn't say anything about the model itself. It specifies where a tool should move so it's just a series of directives that move a tool from place to place at a given speed. Going from Gcode to a model that you can edit is pretty difficult or impossible.
Currently I'm developing a library to manage some stream of data, but at some point I'd like to represent my findings on 3d. I would like to develop a 3D view of my project:
I have:
- All the 3D vertices of one single block
- All the properties related with the object
The question is: Can I do this on python? Which library should I use? Is there any other solution rather than
Depending on what kind of display you are looking for.
if you need to display it as scientific data, there is VTK which propose a great variety of ways to display
if you want to operate your 3d data, display and inspect it at the same time, you can go for pymadcad (a lot of other modules are available for mesh manipulation only, but without display)
if you want a highly flexible rendering pipeline, you can take a look at moderngl, which is very close to the hardware reality by makes everything extremely simple
if you want a high interaction and flexibility in displaying meshes, maybe a game engine, like Panda3D can be more convenient
So I have a shapefile that is 3GB in size and as you can imagine my browser doesn't like it. How can I compress the data I have which is either in lon/lat coordinates or points on an X,Y grid?
I saw a video on Computerphile about Discreet Cosine Transforms for reducing high dimesionality data but being a programmer and not a mathematician I don't know if this is even possible. I have tried to take a point every 10 steps in the file like so: map[0:100000:10] but this had an udesireable and very lossy effect.
I would ideally like to have my data so it would work like Google Earth in which the resolution adjusts to your viewport altitude. So when you zoom in to the map higher freqency data is presented in the viewport, limiting the amount of points but I don't know how they do this and Google return nothing of value.
Last point is that since these are just vectors is there any type of vector compression I could use? I'm not to great at math so as you can imagine when I look into this I just get confused fairly quickly. I uderstand SciPy has some DCT built in and I know it has a whole bunch of other features which I don't understand, perhaps I could use this?
I can answer the "level of detail" part: you can experiment with leaflet (a javascript mapping library). You could then define a "coarse" layer wich is displayed for low zoom levels and "high detail" layers that are only displayed at higher zoom levels. You probably need to capture the map zoomend event and load/unload your layers from there.
One solution to this problem is to use a Web Map Server (WMS) like GeoServer or MapServer that stores your ShapeFile (though a spatial database like PostGIS would be better) on the server and sends a rendered image (often broken down into cacheable tiles) to the browser.
I'm interested in using python to make diagrams representing the size of values based on the size of squares (and optionally their colour). Basically I'm looking for a way to make overviews of a bunch of values like the good old program windirstat does with hard-drive usage (it basically makes a big square representing your harddrive and then smaller squares making up the area inside of it representing different programs, the bigger the square the larger the file, colour indicates the type of file). I'm fairly familiar with matplotlib, and I don't think it's possible to do something like this with it. Is there any other python package that would help? Any suggestions for something more low level if it's not? I guess I could do it manually if I could find a way to draw the boxes programatically (I don't really care about the format, but the option to export SVG as well as PNG would be nice).
Ultimately, it would be nice to have it be interactive like windirstat is, where if you were to hover over a particular square you get more information on it, and if you clicked on it maybe you'd go in and see the makeup of that particular square. I'm only familiar with wxpython for GUI stuff, not sure if it could be used for something like this. For now I'd be happy with just outputting them though.
Thanks a lot!
Alex
Edit:
Thanks guys, both your answers helped a lot.
You're looking for Treemapping algorithms. Once implemented, you can transform the output (which should be rectangles) into plotting commands to anything that can draw layered rectangles.
Edit:
More links and information:
If you don't mind reading papers, the browser-based d3 library provides for 'squarified' treemaps (js implementation). They reference this paper by Bruls, Huizing, and van Wijk. (This is also citation 3 on the wikipedia article)
I'd search on the algorithms listed on the linked Wikipedia article. For instance, they also link to this article, which describes an algorithm for "mixed treemaps". The paper also includes some interesting portions at the end describing transformations into other-than-rectangular shapes.
Squarified certainly appears to be the most common variety around. The above links should give you enough to work towards a solution or, even, directly port the d3 implementation. However, the cost of grokking d3's model (which is something like a declarative form of jQuery) may be somewhat high. At first glance, though, the implementation appears relatively straightforward.
Squaremap does this. I haven't used it (I only know it from RunSnakeRun) and its documentation is severely lacking, but it seems to work.