Skip to content
Advertisement

Plotly displays unnecessary extra values on the x axis of a line chart

I’m plotting this dataframe:

    hour  counted
0      0      0.0
1      1      0.0
2      2      0.0 
3      3      0.0
4      4      0.0
5      5      0.0
6      6      0.0
7      7      0.0
8      8      0.0
9      9      0.0
10    10    792.0
11    11    792.0
12    12      0.0
13    13      0.0
14    14    594.0
15    15    198.0
16    16    198.0
17    17      0.0
18    18      0.0
19    19      0.0
20    20      0.0
21    21      0.0
22    22      0.0
23    23      0.0

Where:

x_values = df4.hour
y_values = df4.counted

layout = go.Layout(title='Line Chart for Successful Transaction per Hour', 
                    xaxis=dict(title='Hour of the day',
                                tickmode = 'linear'),
                    yaxis=dict(title='Transactions'))

But what actually comes out is this:

enter image description here

The x-axis has values of -1 and 24, when I don’t actually need them. There is no “-1 hour” or “24 hour”.

How do I format the plot not to show them?

EDIT: the answer for Plotly is layout_xaxis_range=[0,23], use it in the fig like this:

fig = go.Figure(data=data, layout=layout, layout_xaxis_range=[0,23])

Advertisement

Answer

just plot it using this code:

import matplotlib.pyplot as plt
plt.plot(df4.hour,df4.count)

And you can define xlim and ylim

plt.xlim(0,24)

enter image description here

Take a look at this document :https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.xlim.html

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement