Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable the label when plotting pandas data?

I tried using label=None in the plot command, in which case matplotlib chose the key of the data as a label. I find this behavior unintuitive and expected to have full control over the label when I set it explicitly. How can I disable the label of a plot involving data from a pandas dataframe?

Here is a small example, which shows the behavior:

import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame({'x': [0, 1], 'y': [0, 1]})
plt.plot(df['x'], df['y'], label=None)
plt.legend(loc='best')

This results in the following plot:

enter image description here

In case it matters, I'm currently using matplotlib version 1.5.1 and pandas version 0.18.0 in the following python installed from macports: Python 2.7.11 (default, Mar 1 2016, 18:40:10) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin

like image 473
David Zwicker Avatar asked Mar 22 '16 18:03

David Zwicker


1 Answers

If you pass an empty string then it results in this plot:

import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame({'x': [0, 1], 'y': [0, 1]})
plt.plot(df['x'], df['y'], label='')
plt.legend(loc='best')

enter image description here

like image 130
EdChum Avatar answered Nov 15 '22 09:11

EdChum