Paraview: Can I annotate sources via python scripts? - python

I am visualizing a 3D dataset in paraview and want to annotate certain surface locations by marking them with an object (e.g. cone) and annotating them with text. I want to do this via python script.
Putting the cones is not a problem. But the sources Text and a3DText do not have property for location.
Does anybody know a way how I could do this?
Answer:
After generating the 3D Text source, you can put it into view using Show, then the position property can be changed:
renderView1 = GetActiveViewOrCreate('RenderView')
text = a3DText()
textDisplay = Show(text, renderView1)
textDisplay.Position = [1,1,0]

I found a method that exploits the representation properties (so, if you change visalization, you have to do it again)
Here is what I tried in the paraview gui (4.1):
Tools - Start trace
Source - 3D text
make sure you are visualizing it
in the 3dtext property panel, go to advanced options (the gear symbol)
in the visualization properties there is a field "translation", you can modify that value
I also modified the scale because it was too big for my object
Tools -stop trace : you can see the corresponding python instructions

Related

Is it possible in Python to create a custom made polygon and use that as arrow to produce a stream plot?

i want to create a plot with 13 different arrow styles for a vector field showing the stream of a sea. I want to use very specific arrows which are not bult in FancyArrowPatch. Is ther a possibility to use a selfmade design as arrow in python ? Is it possible to somehow add custom arrow styles to the FancyArrowPatch function ?
I have attached the image I want to reproduce with Python (taken from bsh.de/DE/DATEN/Stroemungen/stroemungen_node.html):
My best try was to produce this one:
Which is not quite satisfying yet. I would like to have the same arrows as seen in the first image. If you have suggestions how to make the image fancier I am open for that too.

Absolute positions in mpld3 graphs

I'm trying to define a custom plugin for mpld3, and I'm struggling with positions. More particularly, by default, SVG generated by mpld3 come with Move and Zoom buttons, which change the view of the graph. When I was trying to display things (like text), I stumbled upon a strange behavior where positions are set relatively to the current view. It means that if I display a text next to a point A(10,10) and then move the view, the point will still be at (10,10) but the text will move because its position is relative to the current view.
So I wanted to think again and start with a minimal example which should work : this example from the mpld3 documentation. In the demo, you can see the behavior I want : positions are absolute (when you move the view, cursor position is set according to the grid)..
But if I copy-paste the exact same code in Pycharm and execute it, positions are relative to the view which is even more strange :
My guess is it's a version problem. I don't know which versions are used in the hosted demo example. I use mpld3==0.5.1, matplotlib==3.2.1 and numpy==1.19.2.
Do you have an idea so I can manage to deal with absolute positions like in the example ?
I've managed to make it work. It turns out that downgrading mpld3 to version 0.3 does what I want. I'm sure there is a better solution (because I can't take advantage of the latest version) but it gets the job done.

How to draw a graph that can indicate the values when the mouse moves to some part of the graph in python and put it on the web page?

I'm writing a web interface for a database of genes values of some experiments with CGI in Python and I want to draw a graph for the data queried. I'm using matplotlib.pyplot, draw a graph, save it, and perform it on the web page. But usually there are many experiments queried hence there are a lot of values. Sometimes I want to know which experiment does one value belong to because it's a big value, whereas it's hard to identify because the picture is small in size. The names of the experiments are long strings so that it will mess the x axis if I put all the experiment names on the x axis.
So I wonder if there is a way to draw a graph that can interact with users, i.e. if I point my mouse to some part on the graph, there would be one small window appears and tells me the exact value and what is the experiment name here. And the most important is, I can use this function when I put the graph on the web page.
Thank you.
What you want is basically D3.js rendering of your plots. As far as I know, there are currently three great ways of achieving this, all under rapid development:
MPLD3 for creating graphs with Matplotlib and serving them as interactive web graphics (see examples in Jake's blog post).
Plotly where you can either generate the plots directly via Plotly or from Matplotlib figures (e.g. using matplotlylib) and have them served by Plotly.
Bokeh if you do not mind moving away from Matplotlib.

Directed graph in python

I am trying to depict the relationship of different data entities with my ETL (extraction transformation loading) pipeline. The final output is a large directed graph. So far I am using Python to extract data relationship. Pydot helps me generate svg file which I can open up using a browser. The graph that I generate is static.
Pydot lets me setup tooltip and allows me to link other html pages with nodes or edges. I am looking for more than that.
A small portion of the graph is shown below
I want to do several things with this graph.
Every node can have several attributes (including name). It is not possible for me to display those attributes because of paucity of space. But as users mouse over (or do other mouse based action) I would like those attributes to show up as "floating" table which user can dismiss if not interested.
Not all node attributes are integer or strings. It can be graphs as well. For example for one of the nodes I may have a bar chart showing how often this data entity is getting loaded in last 7 days. I would like that bar chart to float over as the user moves (clicks) mouse over that node. Currently I am using matplotlib to generate bar / pie charts associated (please see above) with nodes. I link those diagrams with my original directed graph using setURL in pydot. But the user experience is not great since it takes user over to a new page.
I am happy with node layout etc that I get by default from Pydot/GraphViz. I prefer not to do everything from ground up unless it is absolutely necessary.
Ability to highlight only certain part of the graph based on query in node or edge attributes
I read this forum and came across several options in response to questions similar to mine.
gephi
igraph (I played around with igraph which lets me query by vertex
or edge. I couldn't figure out how I can make my final graph
interactive based on user input e.g. floating table on mouse over of
a node etc)
Javascript libraries - sigma.js, arbor.js, d3.js nodebox
networkX
nodebox
I have Python skill but quite novice on Javascript side. I would like to know from experts what can be my best bet (from functionality and ease of use point of view). A browser based solution is preferred.
Any suggestion / help will be really appreciated.
Thanks
Abhijit
Try NetworkX. Node attributes can be anything hashable, so that addresses (at least) your first two bullets.
You will still be using matplotlib to generate the charts. I don't know of a better solution than that.

Draw a map with gps markers and save this image to file

I have some GPS position recordings, which I want to draw into a map (e.g. OpenStreetMap) and save this as an image file.
I'm using python. I've found osm-gps-map as a candidate library to do the visualization, but apparantly the API lacks some functionality to satisfy all of my needs. What I need is a library that does:
draw stuff into a map (e.g. an OSM-based map), i.e. a list of GPS positions.
automatically adjust view (scale/position) to fit in all drawn positions
save this view to an image file
I seriously want to avoid being forced to manually make a screenshot from a widget or a browser window. And if possible I also want to avoid to implement the necessary projection functionality by myself (as in here). Does anyone know a library/toolchain that provides the desired functionality (if possible for use by Python)?
You may want to consider using Basemap for matplotlib. Here is a blog post describing how to use this package with OSM.
There are examples of how to draw custom GPS points on top of OSM background map using Matplotlib Basemap, Matplotlib or Cairo in GeoTiler project: https://github.com/wrobell/geotiler/tree/master/examples.

Categories

Resources