Hide tick label values but keep axis labels

If you use the matplotlib object-oriented approach, this is a simple task using ax.set_xticklabels() and ax.set_yticklabels(). Here we can just set them to an empty list to remove any labels: import matplotlib.pyplot as plt # Create Figure and Axes instances fig,ax = plt.subplots(1) # Make your plot, set your axes labels ax.plot(sim_1[‘t’],sim_1[‘V’],’k’) ax.set_ylabel(‘V’) ax.set_xlabel(‘t’) # … Read more

What is the difference between drawing plots using plot, axes or figure in matplotlib?

The names of objects Matplotlib is strongly object oriented and its principal objects are the figure and the axes (I find the name axes a bit misleading, but probably it’s just me). You can think of the figure as a canvas, of which you typically specify the dimensions and possibly e.g., the background color etc … Read more

How to pick a new color for each plotted line within a figure in matplotlib?

I usually use the second one of these: from matplotlib.pyplot import cm import numpy as np #variable n below should be number of curves to plot #version 1: color = cm.rainbow(np.linspace(0, 1, n)) for i, c in zip(range(n), color): plt.plot(x, y, c=c) #or version 2: color = iter(cm.rainbow(np.linspace(0, 1, n))) for i in range(n): c … Read more

Get default line colour cycle

In matplotlib versions >= 1.5, you can print the rcParam called axes.prop_cycle: print(plt.rcParams[‘axes.prop_cycle’].by_key()[‘color’]) # [u’#1f77b4′, u’#ff7f0e’, u’#2ca02c’, u’#d62728′, u’#9467bd’, u’#8c564b’, u’#e377c2′, u’#7f7f7f’, u’#bcbd22′, u’#17becf’] Or equivalently, in python2: print plt.rcParams[‘axes.prop_cycle’].by_key()[‘color’] In versions < 1.5, this was called color_cycle: print plt.rcParams[‘axes.color_cycle’] # [u’b’, u’g’, u’r’, u’c’, u’m’, u’y’, u’k’] Note that the default color cycle changed … Read more

How to make two plots side-by-side

Change your subplot settings to: plt.subplot(1, 2, 1) … plt.subplot(1, 2, 2) The parameters for subplot are: number of rows, number of columns, and which subplot you’re currently on. So 1, 2, 1 means “a 1-row, 2-column figure: go to the first subplot.” Then 1, 2, 2 means “a 1-row, 2-column figure: go to the … Read more

FutureWarning: elementwise comparison failed; returning scalar, but in the future will perform elementwise comparison

This FutureWarning isn’t from Pandas, it is from numpy, here’s how to reproduce the warning nearer to the source of the trouble: import numpy as np print(np.__version__) # Numpy version ‘1.12.0’ ‘x’ in np.arange(5) #Future warning thrown here FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison False Another … Read more

Remove or adapt border of frame of legend using matplotlib

When plotting a plot using matplotlib: How to remove the box of the legend? plt.legend(frameon=False) How to change the color of the border of the legend box? leg = plt.legend() leg.get_frame().set_edgecolor(‘b’) How to remove only the border of the box of the legend? leg = plt.legend() leg.get_frame().set_linewidth(0.0) For the matplotlib object oriented approach: axes.legend(frameon=False) leg … Read more