How to draw a 2D graph in Python - horizontal bars - python

I would like to make graph like this in Python:
I have made the program in C that will give me combinations I need (here N=2n+|m| iirc), so could I integrate that here somehow?
I made something in Mathematica, but that's a pain in the butt... Any help is appreciated.

I would customize CairoPlot for doing that (http://linil.wordpress.com/2008/09/16/cairoplot-11/ ) --
Cairoplot is a simple and small project to use the powerfull Cairo library to make Graph's.
It does have few, although beauutiful, graphic options, but it is entirely made in Python - it should be possible to subclass a graph class from there to generate plots that fit your need.

You could try using step() in matplotlib
http://matplotlib.sourceforge.net/examples/pylab_examples/step_demo.html

Related

Is there a Python function to compute isosurface end-cap geometry like the 'isocaps' function in Matlab?

I want to get some 3D models defined by implicit functions like F(x,y,z)=0.
It can be done using the 'isosurface' and 'isocaps' functions in MATLAB.
In my case, the constructed models need post-process in Python so it would be better if the modelling can be done in Python.
'mayavi.mlab.Contour3d' and 'plotly.graph_objects.Isosurface' are able to display the isosurface while 'skimage.measure.marching_cubes' can be used to extract the trangler mesh.
Can anyone help me find a way in Python to get the isosurface end-cap?
I'm looking for a way to do the exact same thing. Another user gave me the following solution for my own request.
Is there a way to fill one side of the gyroid surface by using Mayavi?
You have to use an extra tool for visualization to do it. I'm using Mayavi for generating the structures I need but I can't get the surface end-cap by using it.
Maybe the answer to my question can help you out.

Plot vertex as image in Igraph

I'm wondering if it is possible to plot a vertex as image (loaded from a file or directly) in Igraph. Any ideas?
This is definitley possible in the R version of iGraph using the raster function, however a brief search did not reveal any implementation of this function in Python (it's not in the igraph documentation anyway).
If this is essential to your work, then I would consider switching to R, or possibly another tool such as Gephi. For Python, however, you might consider using something like pyvis. This package is small but powerful in terms of visualization. I've been playing around with it over the past few days and its very easy to display a graph with pictures as nodes, and it comes with the added benefit of providing interactive functioning. Take a look at the tutorial here, which will highlight what this package can provide.

Tool to create a python GUI for graph construction

I need to create a GUI for graph construction ("graph" as an abstract representation of a set of objects, not a visual representation of data). The interface will provide a choice of ~5 vertex types and of ~5 edge types. Each vertex will have two data fields: a text label and a file name, which need to be easily editable.
I'm familiar with igraph and have a lot of code written in it. I will use igraph to manipulate the graphs created with this GUI.
Since this will be my first GUI, I'm completely ignorant of what tools are available. Can you please suggest a free library, knowing that eventually the program will need to work on Windows?
EDIT
it seems from the answers I get that I wasn't clear enough. I'm not looking for a way to visualize a graph, but rather for a way to visually create one. By visually, I mean not needing to manually create text files or writing code.
Take a look at xdot.py.
From the homepage
xdot.py is an interactive viewer for graphs written in Graphviz's
dot language.
It uses internally the graphviz's xdot output format as an
intermediate format, and PyGTK and Cairo for rendering.
xdot.py can be used either as a standalone application from
command line, or as a library embedded in your python application.
I like networkx,
from networkx import draw, Graph
from pylab import show
g = Graph()
g.add_edges_from([(1,2),(1,3),(2,4),(2,5)])
draw(g)
show()
which gives,
The only quirk is the requirement for matplotlib to get builtin plotting to work.
If you use python, I think PyQt is a good selection.
What you have to install is listed below:
install Python from here
install PyQt4 from here
But it takes many lines to write GUI application,
it is sometimes better to generate an image to display with image viewer.

Plot functions in Python

I am required to use Python for engineering project. Need to create many graphs, including surface plots. In the past I used Matlab for plotting and really liked it. I was wandering if there is a module/package/extension which bring similar capability into Python.
To be more specific, I need piloting for 2 different reasons.
To understand how functions behave. Something quick and dirty would do it.
Publication/presentation. Ability to add labels, legend, grid, customise colour, axis properties etc.
Try matplotlib, it's pretty extensive and has a shell similar to MATLAB / Mathematica.
I suspect matplotlib.pyplot would be right up your alley.

Scientific Plotting in Python

I have a large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?
Thanks in advance for the help,
--Leo
get matplotlib
The easiest option is matplotlib. Two particular solutions that might work for you are:
1) You can generate a series of plots, each a snapshot at a given time. These can either be displayed as a dynamic plot in matplotlib, where the axes stay the same and the data moves around; or you can save the series of plots to separate files and later combine them to make a movie (using a separate application). There a number of examples in the official examples for doing these things.
2) A simple scatter plot, where the colors of the circles changes with time might work well for your data. This is super easy. See this, for example, which produces this figure
alt text http://matplotlib.sourceforge.net/plot_directive/mpl_examples/pylab_examples/ellipse_collection.hires.png
I'd try rpy. All the power of R, from within python.
http://rpy.sourceforge.net/
rpy is awesome.
Check out the CRAN library for animations,
http://cran.r-project.org/web/packages/animation/index.html
Of course, you have to learn a bit about R to do this, but if you're planning to do this kind of thing routinely in future it will be well worth your while to learn.
If you are interested in scientific plotting using Python then have a look at Mlab: http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html
It allows you to plot 2d / 3d and animate your data and the quality of the charts is really high.
Enthought's Chaco is designed for interactive/updating plots. the api and such takes a little while to get use to, but once you're there it's a fantastic framework to work with.
I have had reasonable success with Python applications generating SVG with animation features embedded, but this was with a smaller set of elements than what you probably have. For example, if your data is about a seismic event, show a circle that shows up when the event happened and grows in size matching the magnitude of the event. A moving indicator over a timeline is really simple to add.
Kaleidoscope (Opera, others maybe, Safari not) shows lots of pieces moving around and I found inspirational. Lots of other good SVG tutorial content on the site too.
You might want to look at PyQwt. It's a plotting library which works with Qt/PyQt.
Several of the PyQwt examples (in the qt4examples directory) show how to create "moving" / dynamically changing plots -- look at CPUplot.py, MapDemo.py, DataDemo.py.

Categories

Resources