Reputation: 24268
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:
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
Upvotes: 6
Views: 9259
Reputation: 393933
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')
Upvotes: 7
Reputation: 20196
Just pass an empty label. Matplotlib doesn't bother making a legend entry in that case. The label=None
argument is the default, which the plotting function detects, telling it to make up a label.
(Of course, in this case, you could just not use plt.legend
...)
Upvotes: 1