-1

i have a dataframe with 850 values.it is consisted by three columns : Datetime , Cloud Coverage and cloud type . i tried to make a plot , putting the datetime in x axis and cloud coverage and cloud type at y axis . But my problem is that due to the fact that there are 850 datetime values there is a black line in x axis

i tried the following code import pandas as pd

import numpy as np
  
from matplotlib import pyplot as plt  
 
import matplotlib as mpl       

import matplotlib.dates as mdates   

x = dfc['Datetime']

y1 = dfc['Cloud coverage']

y2 = dfc['Cloud type'] 

fig, ax1 = plt.subplots()


ax2 = ax1.twinx()

ax1.plot(x , y1, 'b-')

ax2.plot(x , y2, 'r-')
plt.xticks(['02:00','04:00','06:00','08:00','10:00','12:00','14:00','16 
:00','18:00'])                                                                    
    

ax1.set_xlabel('Datetime')

ax1.set_ylabel('Cloud Coverage (%)', color='b')

ax2.set_ylabel('Cloud Type', color='r')

plt.title('Variability of Cloud Coverage and Cloud type during 13th of July')

plt.show()

and the output is the following

[https://i.stack.imgur.com/veMqu.png][1]

how can i fix the x axis in the plot that the last datetime x values are bold ?

1 Answers1

-1

Use plt.xticks to define what values you want to be shown on the x-axis, an example can be seen below:

import matplotlib.pyplot as plt

plt.plot([1,2,3,4], [1,2,3,4])
plt.ylabel('some numbers')
plt.xticks([1,4])
plt.show()

This will show a graph like so:

enter image description here

In your case you'd add a list like ['00:00' , '01:00' , '02:00' ... '23:00'] in the xticks function. Note: in xticks you can also define 'rotation', for the angle you want the values to be at.

Oxin
  • 219
  • 1
  • 11