简体   繁体   English

Seaborn条形图-不同的y轴值?

[英]Seaborn bar plot - different y axis values?

I am very new to coding and just really stuck with a graph I am trying to produce for a Uni assignment 我对编码非常陌生,只是真的停留在尝试为Uni作业生成的图上

This is what it looks like 这就是它的样子

I am pretty happy with the styling my concern is with the y axis. 我对y轴的样式感到非常满意。 I understand that because I have one value much higher than the rest it is difficult to see the true values of the values further down the scale. 我了解,因为我拥有一个比其他值高得多的值,所以很难在更小范围内看到这些值的真实值。

Is there anyway to change this? 反正有改变吗? Or can anyone recommend a different grah type that may show this data mor clearly? 还是有人可以推荐其他可以清楚显示此数据的grah类型?

Thanks! 谢谢!

You can try using a combination of ScalarFormatter on the y-axis and MultipleLocator to specify the tick-frequency of the y-axis values. 您可以尝试使用y轴上的ScalarFormatterMultipleLocator来指定y轴值的刻度频率。 You can read more about customising tricks for data-visualisations here Customising tricks for visualising data in Python 您可以在此处阅读有关数据可视化的自定义技巧的更多信息。

import numpy as np
import seaborn.apionly as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

ax_data = sns.barplot(x= PoliceForce, y = TotalNRMReferrals) # change as per how you are plotting, just for an example
ax_data.yaxis.set_major_locator(ticker.MultipleLocator(40)) # it would have a tick frequency of 40, change 40 to the tick-frequency you want.
ax_data.yaxis.set_major_formatter(ticker.ScalarFormatter())
plt.show()

Based on your current graph, I would suggest lowering the tick-frequency (try with values lower than 100, say 50 for instance). 根据您当前的图表,我建议降低时钟频率(尝试使用小于100的值,例如说50)。 This would present the graph in a more readable fashion. 这将以更具可读性的方式显示图形。 I hope this helps answer your question. 我希望这有助于回答您的问题。

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

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