简体   繁体   中英

How do I change the X axis value on a histogram using matplotlib/seaborn in python?

Here is how the graph currently looks, but I want it to have just 3 bars, s1, s2, and s9 for the x value and the microns on the y, but for some reason there are 5 seperate colors for the bar and the x-axis is just an extenstion of the y axis. 图形

Here is the code: 在此处输入图像描述

在此处输入图像描述

if you are looking for just one bar for each of the columns s1, s2, s9 and the sum of all the columns in those to be the height of each of these bars, you should be using barplot() instead. Get the sum of each column using sum() and then plot it. Below code shows this for some random data. The sum() will get the total for each column and doing a reset_index() will add the column names as a column index. You can try print box_data.sum().reset_index() to understand how the sum data looks like.

Code

data = {'s1': np.random.randint(20,160, size=(100)),
        's2':np.random.randint(16,80, size=(100)),
        's9':np.random.randint(60,170, size=(100))}
box_data=pd.DataFrame(data)

sns.barplot(data = box_data.sum().reset_index(), y=0, x= 'index')

Plot在此处输入图像描述

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