简体   繁体   中英

Python pandas matplotlib how to remove category labels in the plot?

# Example Python program to plot a complex bar chart 

import pandas as pd

import matplotlib.pyplot as plot

 

# A python dictionary

data = {"Car Price":[24050, 34850, 38150],

        "Kerb Weight":[3045, 3572, 3638]

        };

index     = ["Variant1", "Variant2", "Variant3"];

 

# Dictionary loaded into a DataFrame       

dataFrame = pd.DataFrame(data=data, index=index);

 

# Draw a vertical bar chart

dataFrame.plot.bar(rot=15, title="Car Price vs Car Weight comparision for Sedans made by a Car Company");

plot.show(block=True);

This code is from https://pythontic.com/pandas/dataframe-plotting/bar%20chart

The result I would get is

在此处输入图像描述

How can I remove the category box in the top left corner?

Change your second last line to this to remove the legend:

dataFrame.plot.bar(rot=15, title="Car Price vs Car Weight comparision for Sedans made by a Car Company", legend=False)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM