contour plot in bokeh - python

I would like to use pyplot.contour feature in bokeh. Is there any way I can use it?? I know pyplot.pcolormesh and bokeh.plotting.image. Can I use conotur plot with it?

pyplot.contour is part of Matplotlib, not Bokeh. As of Bokeh 2.3.0 there is no built-in contouring function or capability. Recently a MultiPolygons glyph that can support "polygons with holes" was added. This is a first necessary step to being able to have real contour plots in Bokeh. A next step would be for someone to write a set of functions that can accept array inputs and generate the multi-polygon data necessary to drive Bokeh graphics, but this has not been done by anyone yet.
If image contour plots (similar to pcolormesh) or line (unfilled) contours suit your needs, that you can consider using Holoviews, which can generate Bokeh contour plots for those kinds of cases:
http://holoviews.org/reference/elements/bokeh/Contours.html

Related

Bokeh image section

I am using bokehjs from python in order to display 2d gl array as images or heat map.
Generally, in different tools i know, In order to explore the data there is a popular data analysis feature of "section" that you mark on the image and see a 1d graph of the image gl.
Does it exist on bokeh?
If not, what is the best choice of creating it?
I'm not entirely sure what you mean. Do you have 2d data for which you want to select a 1d 'slice' and display it as a graph? Or do you have a 3d cube of data for which want to display a 2d (x,y) image and for a point a graph (z)?
Either way, for sure it's possible with Bokeh, but not out-of-the-box (for as far as i know).
Maybe you are better of looking at project like Holoviews (or its Geoviews) and see if that works for your use case. Holoviews has several backends for rendering, for example one for Bokeh.
See for example the "More detailed example" at their website, move the slider on the right side of the plot for some interactivity:
http://holoviews.org/

Matplotlib alternative for 3D scatter plots

I am having a hard time using Matplotlib to visualize reprojection results of my data in 3 dimensions after applying Principle components analysis or Linear discriminant analysis. After doing a scatter plot, I cannot rotate the data or change the point of view while zooming easily (Rotation axis stays the same even after you zoom, and if you zoom too much points just disappear) and every change takes one second to occur. Matplotlib is very useful but for this specific use case it starts to get very frustrating as it probably wasn't designed for such tasks. Is there an alternative to Matplotlib in Python that can handle 3d scatter plots better and where one could fluidly navigate through the cloud?
An example is shown in the next figure. I have drawn spheres around each data cluster corresponding to a specific class and colored overlapping spheres with red. Now I want to see how these sphere intersect. I think the biggest problem with Matplotlib is that it doesn't allow shifting of the whole graph with the mouse, it only allows rotation around a fixed point, which makes things very messy once you zoom a bit.
matplotlib is not quite mature for 3d graphics :
http://matplotlib.org/mpl_toolkits/mplot3d/faq.html
mplot3d was intended to allow users to create simple 3D graphs with the same “look-and-feel” as matplotlib’s 2D plots. Furthermore, users can use the same toolkit that they are already familiar with to generate both their 2D and 3D plots.
I don't think easy navigation in a 3d plot is easily doable (even 3d scaling is not possible without tweaking the lib). mplot3d was not really intended to be a full-fledged 3D graphics library in the beginning, but more a nice addition for people who needed basic 3D and who were acquainted with matplotlib 2D plot structure.
You might want to take a look at MayaVI (which is pretty good) :
MayaVi2 is a very powerful and featureful 3D graphing library. For advanced 3D scenes and excellent rendering capabilities, it is highly recomended to use MayaVi2.
Note that unlike matplotlib, MayaVI is not yet compatible with Python3 (and might not be in the foreseeable future), so you'll need a Python2 installation.
A very good alternative, but not in Python, is the 3D plot from ILNumerics (http://ilnumerics.net/). It is in .NET
Matplotlib works alright for 3D however, not too fast when interactivity is needed:
https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html
Mayavi is really fast and compatible with Python 3:
https://docs.enthought.com/mayavi/mayavi/mlab.html#id1

Matplotlib to generate such circular plots?

does anyone know if it's possible to generate such plots in matplotlib?
the image is taken from the following page. If not, there another 'python' solution to generate such plots?
You want to use the packange networkx which will take care of the layout and plotting (via matplotlib if you want).

Is there a Python module that can contour data without gridding

I am trying to contour a set of irregularly spaced data (2D contours in this case) without first gridding the data. The data are output from a model and I want the contours to fully honor the underlying data. Is there a Python module with this functionality, perhaps using Delaunay triangulation? Ideally I could export the contours as a shapefile, but could probably work with a matplotlib plot or similar. Also open to other open-source approaches if I can't figure it out in Python.
Thanks
Have a look #
Shapely https://github.com/sgillies/shapely
and
scipy Delaunay¶ http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.Delaunay.html

How to place country boarders as background for a plot with matplotlib?

I have some data made of coordinates and the count of each coordinate which I plot in a heatmap like this:
pyplot.subplot(211)
pyplot.scatter(longitudes, latitudes, c=counts)
pyplot.colorbar()
which is inspired by this great answer here in SO.
If you look closely you can see, that the dots shape the worldmap somehow. To underline this effect I'd like to put the real country boarders (simply drawn would be enough) as background to my plot. Is this possible with matplotlib? Maybe there is some (hidden) builtin in matplotlib?
You can likely achieve this if you have some image of the world map that you want as a background. You can read this into a numpy array and plot the image. Then you should be able to add your scatter plot overtop of the image. This matplotlib cookbook example shows how to insert images and such. There is also the matplotlib image tutorial that may be of use.
I've not used it, but you may also be interested in the basemap toolkit for matplotlib. In particular, the section on drawing a map background mentions specifically a drawcountries() method.

Categories

Resources