0

I am very new to coding and just really stuck with a graph I am trying to produce for a Uni assignment

This is what it looks like

I am pretty happy with the styling my concern is with the y axis. 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?

Thanks!

Sam
  • 81
  • 2
  • 10
  • I think this might help: https://stackoverflow.com/questions/27019153/how-to-scale-seaborns-y-axis-with-a-bar-plot – Lea Mar 01 '19 at 20:56

1 Answers1

1

You can try using a combination of ScalarFormatter on the y-axis and MultipleLocator to specify the tick-frequency of the y-axis values. 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). This would present the graph in a more readable fashion. I hope this helps answer your question.

JChat
  • 784
  • 2
  • 13
  • 33
  • i have tried this and changed the x and y titles to the correct ones. I now get the error code 'ValueError: Could not interpret input 'Police force sent NRM referral for Crime Recording' – Sam Mar 03 '19 at 17:04
  • What is the input you are providing for the plot? Could not interpret input 'Police force sent NRM referral for Crime Recording' - Are you trying to plot a string? It looks like you are trying to pass a String as an input to barplot(). Can you please post the entire traceback (stack trace of errors you get, including the line numbers etc. where the error occurs). It will be easier to understand it thereby. – JChat Mar 03 '19 at 17:32
  • Is your data in a data frame? Please post some code of what you have done as SO is meant for us to help you with coding problems. It would be helpful for us to answer your question if you edit your question with some code and traceback of errors. – JChat Mar 03 '19 at 17:36
  • Thanks! I realised I had not been inputting the df correctly - all sorted now – Sam Mar 05 '19 at 13:22
  • Sounds great. If this answer helped you in some way, could you kindly consider upvoting/accepting it if you would like. Thanks! – JChat Mar 05 '19 at 16:43