I’m plotting this dataframe:
JavaScript
x
26
26
1
hour counted
2
0 0 0.0
3
1 1 0.0
4
2 2 0.0
5
3 3 0.0
6
4 4 0.0
7
5 5 0.0
8
6 6 0.0
9
7 7 0.0
10
8 8 0.0
11
9 9 0.0
12
10 10 792.0
13
11 11 792.0
14
12 12 0.0
15
13 13 0.0
16
14 14 594.0
17
15 15 198.0
18
16 16 198.0
19
17 17 0.0
20
18 18 0.0
21
19 19 0.0
22
20 20 0.0
23
21 21 0.0
24
22 22 0.0
25
23 23 0.0
26
Where:
JavaScript
1
8
1
x_values = df4.hour
2
y_values = df4.counted
3
4
layout = go.Layout(title='Line Chart for Successful Transaction per Hour',
5
xaxis=dict(title='Hour of the day',
6
tickmode = 'linear'),
7
yaxis=dict(title='Transactions'))
8
But what actually comes out is this:
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:
JavaScript
1
2
1
fig = go.Figure(data=data, layout=layout, layout_xaxis_range=[0,23])
2
Advertisement
Answer
just plot it using this code:
JavaScript
1
3
1
import matplotlib.pyplot as plt
2
plt.plot(df4.hour,df4.count)
3
And you can define xlim
and ylim
JavaScript
1
2
1
plt.xlim(0,24)
2
Take a look at this document :https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.xlim.html