I want the similar visualization as shown below using Bokeh. As I am new to Bokeh , I might be wondering is there any code that is as concise as the below one using Seaborn ?
My main focus is how to write code for same visualization in Bokeh
dataset
data = pd.read_csv('http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv',index_col = 0)
Plotting the dataset
import seaborn as sns
sns.pairplot(data, x_vars = ['TV', 'Radio','Newspaper'], y_vars = ['Sales'],
size =7, aspect =.7, kind = 'reg')
Also the code in Seaborn doesn't require to enter the best fitted line . It automatically generates the best fitted line in the graph with a shadow of confidence interval . Is this kind of plotting possible in Bokeh ?
The above charts are certainly possible with Bokeh, in the sense that Bokeh could draw them, without any question. But it would take some work, and require more code, than with Seaborn. Basically you'd have to compute all the coordinates and set up all the glyphs "by hand". As of Bokeh 0.12.2, there is not currently any comparable "single line" high level function or chart in bokeh.charts.
Adding more high level chart types lie this to bokeh.charts is definitely something that we'd like, but it will probably require motivated new contributors to make that happen. Fortunately, this area of Bokeh is pure-python and probably the most approachable for new contributors. If you are possibly interested in contributing to Bokeh, I encourage you to reach out on the public mailing list or gitter chat channel. We are always happy to answer questions and help people get started.
Related
I'm new to plotly/plotly express and i'm having a really hard time finding any working example other than the documentation examples for the library (which are really basic and standard).
I have, let's say a scatter plot, in plotly express:
fig = px.scatter(any_random_data)
And i want to add to that plot an image in a fixed (x,y) position, but i don't know (and can't find!) if there is any kind of method for that.
I've seen there is an add_trace() method to add traces to the plot (i guess), is there any similar function for adding images? (Like add_image() or something)
EDIT: For some reason I've been downvoted twice for posting this question (it hurts ppl) so I've rejigged it.
How do you combine multiple heatmaps in a stacked way with same color scale like to following image?
Additionally, does anyone know how to create the Augmented suffix tree?
Background:
I've worked through the python jupyter notebooks at the following link on how to create the heatmaps of (any) daily consumption profiles using seaborn
http://www.datadrivenbuilding.org/
...however there's a realllllllly cool combination graphic I'd love to be able to reproduce.
That image is an edited version of an image from this paper:
C. Miller, Z. Nagy, A. Schlueter, Automated daily pattern filtering of
measured building performance data, Automation in Construction 49,
Part A (2015) 1–17. doi:10.1016/j.autcon.2014.09.004. URL
http://www.sciencedirect.com/science/article/pii/S0926580514002015
They came up with the visualisation techniques themselves and describe them there. It looks like C. Miller is the one who wrote the notebook that you already found that shows how to draw the stacked heatmaps.
The augmented suffix tree is a type of visualization called a Sankey Diagram. You can plot these very beautifully using Plotly for example, or pySankey if you want to use matplotlib.
I'm having some trouble visualizing a certain dataset that I have in a contour plot. The issue is that I have a bunch of datapoints (X,Y,Z) for which the Z values range from about 2 to 0, where a lot of the interesting features are located in the 0 to 0.3 range. Using a normal scaling, they are very difficult to see, as illustrated in this image:
Now, I have thought about what else to do. Of course there is logarithmic scaling, but then I first need to think about some sort of mapping, and I am not 100% sure how one would do that. Inspired by this question one could think of a mapping of the type scaling(x) = Log(x/min)/Log(max/min) which worked reasonably well in that question.
Also interesting was the followup discussed here.
where they used some sort of ArcSinh scaling function. That seemed to enlarge the small features quite well, proportionally to the whole.
So my question is two fold in a way I suppose.
How would one scale the data in my contour plot in such a way that the small amplitude features do not get blown away by the outliers?
Would you do it using either of the methods mentioned above, or using something completely different?
I am rather new to python and I am constantly amazed by all the things that are already out there, so I am sure there might be a built in way that is better than anything I mentioned above.
For completeness I uploaded the datafile here (the upload site is robustfiles.com, which a quick google search told me is a trustworthy website to share things like these)
I plotted the above with
data = np.load("D:\SavedData\ThreeQubitRess44SpecHighResNormalFreqs.npy")
fig, (ax1) = plt.subplots(1,figsize=(16,16))
cs = ax1.contourf(X, Y, data, 210, alpha=1,cmap='jet')
fig.colorbar(cs, ax=ax1, shrink=0.9)
ax1.set_title("Freq vs B")
ax1.set_ylabel('Frequency (GHz)'); ax1.set_xlabel('B (arb.)')
Excellent question.
Don't scale the data. You'll be looking for compromises in ranges with many scaling functions.
Instead, use a custom colormap. That way, you won't have to remap your actual data and can easily customize the visualization of the regions you'd like to highlight. Another example can be found in the scipy cookbook and there's quite a few more on the internet.
Another option is to break the plot into 2 separate regions by breaking the axis like so
I have been looking for a way to be able to select which series are visible on a plot, after a plot is created.
I need this as i often have plots with many series. they are too many to plot at the same time, and i need to quickly and interactively select which series are visible. Ideally there will be a window with a list of series in the plot and checkboxes, where the series with the checked checkbox is visible.
Does anyone know if this has been already implemented somewhere?, if not then can someone guide me of how can i do it myself?
Thanks!
Omar
It all depends on how much effort you are willing to do and what the exact requirements are, but you can bet it has already been implemented somewhere :-)
If the aim is mainly to not clutter the image, it may be sufficient to use the built-in capabilities; you can find relevant code in the matplotlib examples library:
http://matplotlib.org/examples/event_handling/legend_picking.html
http://matplotlib.org/examples/widgets/check_buttons.html
If you really want to have a UI, so you can guard the performance by limiting the amount of plots / data, you would typically use a GUI toolbox such as GTK, QT or WX. Look here for some articles and example code:
http://eli.thegreenplace.net/2009/05/23/more-pyqt-plotting-demos/
A list with checkboxes will be fine if you have a few plots or less, but for more plots a popup menu would probably be better. I am not sure whether either of these is possible with matplotlib though.
The way I implemented this once was to use a slider to select the plot from a list - basically you use the slider to set the index of the series that should be shown. I had a few hundred series per dataset, so it was a good way to quickly glance through them.
My code for setting this up was roughly like this:
fig = pyplot.figure()
slax = self.fig.add_axes((0.1,0.05,0.35,0.05))
sl = matplotlib.widgets.Slider(slax, "Trace #", 0, len(plotlist), valinit=0.0)
def update_trace():
ax.clear()
tracenum = int(np.floor(sl.val))
ax.plot(plotlist[tracenum])
fig.canvas.draw()
sl.on_changed(update_trace)
ax = self.fig.add_axes((0.6, 0.2, 0.35, 0.7))
fig.add_subplot(axes=self.traceax)
update_trace()
Here's an example:
Now that plot.ly has opened sourced their libraries, it is a really good choice for interactive plots in python. See for example: https://plot.ly/python/legend/#legend-names. You can click on the legend traces and select/deselect traces.
If you want to embed in an Ipython/Jupyter Notebook, that is also straightforward: https://plot.ly/ipython-notebooks/gallery/
I'm preparing a set of reports using open source ReportLab. The reports contain a number of charts. Everything works well so far.
I've been asked to take a (working) bar chart that shows two series of data and overlay a fitted curve for each series.
I can see how I could overlay a segmented line on the bar graph by creating both a line chart and bar chart in the same ReportLab drawing. I can't find any reference for fitted curves in ReportLab, however.
Does anyone have any insight into plotting a fitted curve to a series of data in ReportLab or, failing that, a suggestion about how to accomplish this task (I'm thinking that chart would need to be produced in matplotlib instead)?
I would recommend using MatPlotLib. This is exactly the sort of thing it's designed to handle and it will be much easier than trying to piece together something in ReportLab alone, especially since you'll have to do all the calculation of the line on your own and figure out the details of how to draw it in just the right place. MatPlotLib integrates easily with ReportLab; I've used the combination several times with great results.