2D grid data visualization in Python

Matplotlib has the imshow method for plotting arrays: import matplotlib as mpl from matplotlib import pyplot import numpy as np # make values from -5 to 5, for this example zvals = np.random.rand(100,100)*10-5 # make a color map of fixed colors cmap = mpl.colors.ListedColormap([‘blue’,’black’,’red’]) bounds=[-6,-2,2,6] norm = mpl.colors.BoundaryNorm(bounds, cmap.N) # tell imshow about color map … Read more

How to visualize RNN/LSTM gradients in Keras/TensorFlow?

Gradients can be fetched w.r.t. weights or outputs – we’ll be needing latter. Further, for best results, an architecture-specific treatment is desired. Below code & explanations cover every possible case of a Keras/TF RNN, and should be easily expandable to any future API changes. Completeness: code shown is a simplified version – the full version … Read more

Matplotlib autoscale

Not sure if this what you wanted, but I can change it if this was not what you were looking for. import matplotlib.pyplot as plt from matplotlib.collections import LineCollection import pylab as p fig = plt.figure() pts1 = [] pts2 = [] for i in range(100): pts1.append([i,i]) pts2.append([-i-3,-i]) lines = LineCollection([pts1,pts2], linestyles=”solid”) subplt = fig.add_subplot(111,aspect=”equal”) … Read more

Is it possible to add hatches to each individual bar in seaborn.barplot?

You can loop over the bars created by catching the AxesSubplot returned by barplot, then looping over its patches. You can then set hatches for each individual bar using .set_hatch() Here’s a minimal example, which is a modified version of the barplot example from here. import matplotlib.pyplot as plt import seaborn as sns # Set … Read more

Can Google Charts support dual y-axis (v-axis)?

It took me a while, to figure this out, but Google Charts does support dual Y-axis (v-axis). I want to use the Javascript API and not the HTML interface. This example can be tested here: http://code.google.com/apis/ajax/playground/?type=visualization#line_chart Replace all of that code with this code showing how to have two different Y-axis scales: function drawVisualization() { … Read more

multi_line hover in bokeh

As of Bokeh 0.12.4 (earlier, actually but I forget the exact release) the hover tool supports mutli_line: from collections import defaultdict import numpy as np from scipy.stats import norm from bokeh.plotting import show, figure from bokeh.models import ColumnDataSource, HoverTool from bokeh.palettes import Viridis6 RT_x = np.linspace(118, 123, num=50) mass_spec = defaultdict(list) for scale, mz in … Read more

How to draw rectangle outside of the plot frame in Matplotlib

I think a better way is to use the clip_on=False option for Rectangle: import random import matplotlib.pyplot as pyplot x = random.sample(range(50), 50) y= random.sample(range(50), 50) fig = pyplot.figure() ax = pyplot.subplot(111) ax.scatter(x,y,label=”a”) ax.set_aspect(‘equal’) ax.set_xlim(0,60) ax.set_ylim(0,60) ax.plot([0,60], [0, 60], color=”k”, linestyle=”-“, linewidth=1.25) ax.add_patch(pyplot.Rectangle((0,60),60, 10,facecolor=”silver”, clip_on=False,linewidth = 0)) TITLE = ax.text(26,61, r’$\mathregular{Title}$’,fontsize = 14,zorder = 5, … Read more

OpenCV: How to visualize a depth image

According to the documentation, the function imshow can be used with a variety of image types. It support 16-bit unsigned images, so you can display your image using cv::Mat map = cv::imread(“image”, CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH); cv::imshow(“window”, map); In this case, the image value range is mapped from the range [0, 255*256] to the range [0, … Read more