python reader 图形给出空白画布
python reader graph gives a blank canvass
Mtcars
是 R 中的 public 数据集。我不确定它是 python.
中的 public 数据集
mtcars <- mtcars
我在 R 中创建了这个箱线图,我正在做的部分工作是使用 reorder()
函数对 y 轴重新排序。
ggplot(mtcars, aes(x = mpg, y = reorder(origin, mpg), color = origin)) +
geom_boxplot() +
theme(legend.position = "none") +
labs(title = "Mtcars", subtitle = "Box Plot") +
theme(plot.title = element_text(face = "bold")) +
ylab("country")
现在 python 我有我用 seaborn 创建的箱线图:
plt.close()
seaborn.boxplot(x="mpg", y="origin", data=mtcars)
plt.suptitle("Mtcars", x=0.125, y=0.97, ha='left', fontweight = 'bold')
plt.title("boxplot", loc = 'left')
plt.show()
我现在正在尝试渲染它,但对 R 的同样处理方式不起作用。
plt.close()
seaborn.boxplot(x="mpg", y=reorder("origin", 'mpg'), data=mtcars)
plt.suptitle("Mtcars", x=0.125, y=0.97, ha='left', fontweight = 'bold')
plt.title("boxplot", loc = 'left')
plt.show()
它不起作用并不奇怪,因为它是一种不同的语言;我知道!但是我如何使用 Seaborn 在 python 中进行重新排序?我无法理解这是否是绘图过程的一部分。
您可以计算自定义订单并将其提供给 seaborn 的箱线图 order
参数:
import seaborn as sns
mtcars = sns.load_dataset('mpg')
order = mtcars.groupby('origin')['mpg'].median().sort_values(ascending=False)
sns.boxplot(x="mpg", y="origin", data=mtcars, order=order.index)
plt.suptitle("Mtcars", x=0.125, y=0.97, ha='left', fontweight = 'bold')
plt.title("boxplot", loc = 'left')
plt.show()
注意。 order
也像一个过滤器,因此如果 non-existent 中的值缺失,它们将在图表中被省略
输出:
Mtcars
是 R 中的 public 数据集。我不确定它是 python.
mtcars <- mtcars
我在 R 中创建了这个箱线图,我正在做的部分工作是使用 reorder()
函数对 y 轴重新排序。
ggplot(mtcars, aes(x = mpg, y = reorder(origin, mpg), color = origin)) +
geom_boxplot() +
theme(legend.position = "none") +
labs(title = "Mtcars", subtitle = "Box Plot") +
theme(plot.title = element_text(face = "bold")) +
ylab("country")
现在 python 我有我用 seaborn 创建的箱线图:
plt.close()
seaborn.boxplot(x="mpg", y="origin", data=mtcars)
plt.suptitle("Mtcars", x=0.125, y=0.97, ha='left', fontweight = 'bold')
plt.title("boxplot", loc = 'left')
plt.show()
我现在正在尝试渲染它,但对 R 的同样处理方式不起作用。
plt.close()
seaborn.boxplot(x="mpg", y=reorder("origin", 'mpg'), data=mtcars)
plt.suptitle("Mtcars", x=0.125, y=0.97, ha='left', fontweight = 'bold')
plt.title("boxplot", loc = 'left')
plt.show()
它不起作用并不奇怪,因为它是一种不同的语言;我知道!但是我如何使用 Seaborn 在 python 中进行重新排序?我无法理解这是否是绘图过程的一部分。
您可以计算自定义订单并将其提供给 seaborn 的箱线图 order
参数:
import seaborn as sns
mtcars = sns.load_dataset('mpg')
order = mtcars.groupby('origin')['mpg'].median().sort_values(ascending=False)
sns.boxplot(x="mpg", y="origin", data=mtcars, order=order.index)
plt.suptitle("Mtcars", x=0.125, y=0.97, ha='left', fontweight = 'bold')
plt.title("boxplot", loc = 'left')
plt.show()
注意。 order
也像一个过滤器,因此如果 non-existent 中的值缺失,它们将在图表中被省略
输出: