0

I have a DataFrame that looks something like this:

df = [4, -1, 5, -32, 4, -32, -1]

I want to set the xticks like this:

tick_locs = [-30, -10, 0, 10, 30, 100, 300, 1000, 3000]
plt.xticks(tick_locs, tick_locs)

That gives me a weird graph: enter image description here

I can set the ticks to all positive, but that won't give me negative numbers on the x-axis:

tick_locs = [10, 30, 100, 300, 1000, 3000]
plt.xticks(tick_locs, tick_locs)

enter image description here

Any idea how to get the negative ticks marks?

P.S. The data is set up as logged, but the x-axis is set to show the actual numbers:

bin_edges = 10 ** np.arange(-0.1, np.log10(planes_df['ArrDelay'].max())+0.1, 0.1)
plt.hist(planes_df['ArrDelay'], bins = bin_edges)
plt.xscale('log')
tick_locs = [10, 30, 100, 300, 1000, 3000]
plt.xticks(tick_locs, tick_locs)
5
  • 4
    Are you trying to show negative numbers on a logarithmic scale? How is this supposed to work? Commented Nov 10, 2019 at 23:13
  • Also, including 0 in a logscale create problems Commented Nov 10, 2019 at 23:23
  • @ImportanceOfBeingErnest see the addition above. Commented Nov 10, 2019 at 23:25
  • 1
    Maybe you can explain in your own words where on a logarithmic scale you would expect negative numbers to show up and why. Commented Nov 10, 2019 at 23:28
  • @ImportanceOfBeingErnest I can't explain how. Should I just not use a histogram? I can display this as a bar chart. Commented Nov 10, 2019 at 23:41

1 Answer 1

1

Try removing the line plt.xscale('log'). This will make the x-axis scale linear. A logarithmic axis cannot display non-positive values, as log(x) is undefined for x <= 0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.