a Pythonic way to draw a bump chart - python

I have a csv file that contains data I want to represent using a bump chart (as an example )
http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0003nk
BUT I need to have some control over the formatting and would like to approach this in the most Pythonic way possible ( I am fairly new to Python using 3.5) so wonder if anyone could tell me which graphing package gives me the kind of control that would allow me to:
draw a bump chart
specify the font (Gill Sans)
specify the number of pixels per centimeter squared (about 10000)
If anyone has a package that is in the open source environment that would be the best fit for me I would be grateful.

SO I have accidently found my answer myself in the example I gave. A VERY splendid man called Pascal Schetalat has an EXCELLENT implementation in Python using Numpy and Pandas. Here is the link
http://nbviewer.ipython.org/gist/pascal-schetelat/8382651
thank YOU Pascal

Related

Creating a strip chart in python along a kiloemeter segment

I am hoping to create some comparison plots using python- see the image included. They show categories with a start and end point using different colors, and divided by year, km section etc 9see image)
Could someone point me to a good starting place for this? I didn't see the right type of plot in matplotlib so I am wondering if there is another python module that could accomplish this.
This was done using a roundabout method in CAD but I'm sure there's a cleaner way in python. I'm still a beginner python user so I'm not savvy with what modules could accomplish this sort of chart

How to add wind vectors over a density heatmap?

I have this density heatmap generated using Python Plotly package:
Now I need to add wind vectors over the heatmap. I would like to use quiver plots if possible, but currently I want to know how to add any kind of plot to a mapbox.
I have only found this example but the source code in the Plotly Chart Studio doesn't load so I don't know how to do it, also I need it in 2D:
I am not 100% sure if it is helpful but there is a software called QGIS (it's free). It is much easier to work with geospatial data there. Also, try rasterio library. It may have some functions like that (library for geospatial analyze)
I once used the velocity capability of ipyleaflet https://ipyleaflet.readthedocs.io/en/latest/api_reference/velocity.html
It is not using plotly but could be a good replacement for this kind of map until you find a better solution.

How to control facet height and width in plotnine?

I have seen this post regarding ggplot2:
How to automatically adjust the width of each facet for facet_wrap?
I was wondering:
how can I achieve the same in plotnine? I haven't found anything similar to grob. I would need it for a plot that is part of a python3 pipeline so I really don't want to convert part of the code to R.
Thanks for the help!
I checked the post you linked and proposed a far simpler solution, which is to use facet_grid rather than facet_wrap. When you use facet_grid, you can specify space='free' to automatically adjust the size of the facets, rather than the size of the scales only with scales=. There does not appear to be an option with facet_wrap to specify space= (only scales=).
I do not have direct experience using plotnine, but a quick check here shows that there exists a similar function that includes both space= and scales= arguments.

Visual representation of a Ranking over time (image provided)

The graph below shows a ranking of countries at 10 different points. The cool thing with this graph is that it allows you to track changes in the ranking over time. I want to create create something similar, but I have no idea how it was created...
My guess is that it was created using some design tool like adobe indesign, but my hope is that there might be some other tools for obtaining such a graphic (maybe even a way to do it within Mathematica or Python?)?
Any ideas and/or suggestions on where to look would be much appreciated.
PS: In case I did not post this in the most appropriate of stackExchange's many forums--my apology.
it is called a bump chart, you can learn how to make it with python in this article
How to make a bump chart

3D/4D graphics with Python and wxPython?

In my day job as a PhD student, I do geological modeling. In my spare time (mainly for fun), I am learning Python and trying to write a simple program to view 3D geocellular models.
geological model http://img710.imageshack.us/img710/6503/sgems.png
The geocellular model is just a 3D grid where every grid cell has some value (as shown in the right figure). So, I would want my viewer to be able to display a 3D grid model like the picture on the right side. As well, I would like it to be able to display cross sections through the model in the x, y and z directions (this is shown in the left figure).
I would also want the models to be able to rotate around all three axes and zoom in and out.
I've done some preliminary investigation (mainly here) and it seems like VisVis and VTK are two potential options. I am trying to use wxPython for the main GUI and it looks like both options will work with wxPython as far as I can tell.
Questions:
Am I right when I say that I think VisVis and VTK would work for what I want? Is one preferable to the other?
Which of these two options would be the easiest to implement?
Is there another option that I also should consider?
Keep in mind that I'm newish to Python and very new to wxPython.
What you are looking for is called voxel visualization, voxel grid or such. I would seriously consider MayaVi (never used it, but I keep eye on it), it seems to have something very close here.
Paraview, built atop VTK just like MayaVi, might be a good option, too.
I think going straight to VTK for visualization is difficult, it is too low-level and will probably make you just frustrated. That said, you will want to save your data in as VTK datasets for opening in MayaVi/Paraview; it is not difficult, you just have to pick the right structure (vtkGrid, vtkUnstructedGrid, ...).
In my case, I chose to use directly the VTK bindings for Python. To be honest I found it simpler to get going with VTK than Mayavi, partly because the documentation is better (many many examples!). It felt like Mayavi was adding another layer of complexity on my way to get the job done. But tom10 is right. After you've started, using Mayavi may be easier.
Apart from that, Mayavi offers a library called TVTK which is a more pythonic version of the VTK bindings but in the end I chose plain VTK in order to minimize the number of dependencies. But you should check it out. Perhaps it will be just what you are searching for.
At the beginning I found very helpful this tutorial. It is not about Python, it is about tcl, but translating the examples is trivial and it helps you understand the way vtk works.
Also, in order to get you started, you can check the examples at the VTK Wiki. If they are not enough, you can always check the C++ examples and translate them to Python. The translation is not difficult as the names of methods and properties are the same. If you do, you are encouraged to add the examples at the wiki. There are even more examples in the source.
While you are learning VTK, you will (re)discover that Ipython is awesome! Having the whole VTK namespace at your fingertips helps enormously.
In case you need more specific help, the vtk-users mailing list is quite active. Lastly there are books about VTK, and some of them are free!They are not about Python though.
I haven't tried wxPython and VTK together, but that is because I prefer PyQt4 over wxPython. AFAIK there are no problems with the integration of VTK with either library. In any case, before spending time writing a GUI, check out thoroughly ParaView. It probably already does what you want, and if it doesn't, it is python scriptable too! (I've never checked it though).
Just as a simple example of using Mayavi's mlab interface to do this (With some geologic data, even!):
from mayavi import mlab
import geoprobe
vol = geoprobe.volume('Volumes/example.vol')
data = vol.load() #"data" here is just a 3D numpy array of uint8's
fig = mlab.figure(bgcolor=(1., 1., 1.), fgcolor=(0., 0., 0.), size=(800,800))
grid = mlab.pipeline.scalar_field(data)
# Have things display in kilometers with no vertical exxageration
# Each voxel actually represents a 12.5 by 18.5 by 5 meter volume.
grid.spacing = [vol.dxW / 1000, vol.dyW / 1000, vol.dz / 1000]
# Now, let's display a few cut planes. These are interactive, and are set up to
# be dragged around through the volume. If you'd prefer non-interactive cut
# planes, have a look at mlab.pipeline.scalar_cut_plane instead.
orientations = ['x', 'x', 'y', 'z']
starting_positions = [vol.nx//4, 3*vol.nx//4, vol.ny//2, vol.nz]
for orientation, start_pos in zip(orientations, starting_positions):
plane = mlab.pipeline.image_plane_widget(grid, colormap='gray',
plane_orientation='%s_axes' % orientation, slice_index=start_pos)
# High values should be black, low values should be white...
plane.module_manager.scalar_lut_manager.reverse_lut = True
mlab.show()
(The data and data-format-handling code (the geoprobe module) are available here: http://code.google.com/p/python-geoprobe/ )
While I'd agree that learning VTK is better in the long run, you can get up-and-running quite quickly with Mayavi. The big advantage is not having to jump through hoops to get your data into VTK format. TVTK and Mayavi allow you to directly use numpy arrays.
If you want an easier way of getting into the VTK/MayaVi world (see eudoxos' fine answer), look at the mlab API to it. This brings matplotlib-like convenience to basic volume visualizations and I've yet to find the need to dig deeper into the underlying platform.
vpython is simpler to use than mayavi, but it has fewer features.
http://vpython.org/contents/bounce_example.html

Categories