Rotating axes label text in 3D

As a workaround, you could set the direction of the z-label manually by: ax.zaxis.set_rotate_label(False) # disable automatic rotation ax.set_zlabel(‘label text’, rotation=90) Please note that the direction of your z-label also depends on your viewpoint, e.g: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fg = plt.figure(1); fg.clf() axx = [fg.add_subplot(4,1,1+i, projection=’3d’) for i in range(4)] … Read more

There is a class matplotlib.axes.AxesSubplot, but the module matplotlib.axes has no attribute AxesSubplot

Heh. That’s because there is no AxesSubplot class.. until one is needed, when one is built from SubplotBase. This is done by some magic in axes.py: def subplot_class_factory(axes_class=None): # This makes a new class that inherits from SubplotBase and the # given axes_class (which is assumed to be a subclass of Axes). # This is … Read more

How can I use matplotlib.pyplot in a docker container?

Interestingly, I found quite nice and thorough solutions in ROS community. http://wiki.ros.org/docker/Tutorials/GUI For my problem, my final choice is the second way in the tutorial: docker run –rm -it \ –user=$(id -u) \ –env=”DISPLAY” \ –workdir=/app \ –volume=”$PWD”:/app \ –volume=”/etc/group:/etc/group:ro” \ –volume=”/etc/passwd:/etc/passwd:ro” \ –volume=”/etc/shadow:/etc/shadow:ro” \ –volume=”/etc/sudoers.d:/etc/sudoers.d:ro” \ –volume=”/tmp/.X11-unix:/tmp/.X11-unix:rw” \ deepaul python test.python

How to plot a density map in python?

Here is my aim at a more complete answer including choosing the color map and a logarithmic normalization of the color axis. import matplotlib.pyplot as plt import matplotlib.cm as cm from matplotlib.colors import LogNorm import numpy as np x, y, z = np.loadtxt(‘data.txt’, unpack=True) N = int(len(z)**.5) z = z.reshape(N, N) plt.imshow(z+10, extent=(np.amin(x), np.amax(x), np.amin(y), … Read more

In Matplotlib, is there a way to know the list of available output format

If you create a figure, you can get the available supported file format with the canvas object : import matplotlib.pyplot as plt fig = plt.figure() print fig.canvas.get_supported_filetypes() >>> { ‘svgz’: ‘Scalable Vector Graphics’, ‘ps’: ‘Postscript’, ’emf’: ‘Enhanced Metafile’, ‘rgba’: ‘Raw RGBA bitmap’, ‘raw’: ‘Raw RGBA bitmap’, ‘pdf’: ‘Portable Document Format’, ‘svg’: ‘Scalable Vector Graphics’, ‘eps’: … Read more

How to set xlim and xticks after plotting time-series data

It works for me (with pandas 0.16.2) if I set the x-axis limits using pd.Timestamp values. Example: import pandas as pd # Create a random time series with values over 100 days # starting from 1st March. N = 100 dates = pd.date_range(start=”2015-03-01″, periods=N, freq=’D’) ts = pd.DataFrame({‘date’: dates, ‘values’: np.random.randn(N)}).set_index(‘date’) # Create the plot … Read more

how to handle an asymptote/discontinuity

By using masked arrays you can avoid plotting selected regions of a curve. To remove the singularity at x=2: import matplotlib.numerix.ma as M # for older versions, prior to .98 #import numpy.ma as M # for newer versions of matplotlib from pylab import * figure() xx = np.arange(-0.5,5.5,0.01) vals = 1/(xx-2) vals = M.array(vals) mvals … Read more

How to make two markers share the same label in the legend

Note that in recent versions of matplotlib you can achieve this using class matplotlib.legend_handler.HandlerTuple as illustrated in this answer and also in this guide: import matplotlib.pyplot as plt from matplotlib.legend_handler import HandlerTuple fig, ax1 = plt.subplots(1, 1) # First plot: two legend keys for a single entry p2, = ax1.plot([3, 4], [2, 3], ‘o’, mfc=”white”, … Read more