简体   繁体   English

如何调整Matplotlib和Seaborn显卡的间距?

[英]How to adjust the spacing of Matplotlib and Seaborn graphics?

I'm not finding a function or ways to adjust my X axis, which contains many values, I wanted to sort them into a top 10, but I couldn't and the X axis was this mess with the values.我没有找到 function 或调整我的 X 轴的方法,其中包含许多值,我想将它们排序到前 10 名,但我找不到,X 轴与这些值混在一起。

在此处输入图像描述 在此处输入图像描述

Use order=order[:10] to limit the plot to the 10 highest.使用order=order[:10]将 plot 限制为最高 10。 Use ax.tick_params(axis='x', rotation=30) to rotate the ticks to make them easier to read.使用ax.tick_params(axis='x', rotation=30)旋转刻度以使其更易于阅读。

Here is some code to test and show how it looks like:下面是一些代码来测试和展示它的样子:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

N = 300
cars = pd.DataFrame({'CarName': [f'name_{n}' for n in np.random.randint(1, 30, N)]})
order = cars['CarName'].value_counts().index
ax = sns.countplot(cars['CarName'], data=cars, palette='rainbow', order=order[:10])
ax.tick_params(axis='x', rotation=30)
plt.tight_layout()
plt.show()

示例图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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