Changing and altering ranges of x and y axis in a line graph in MatplotLib

Multi tool use
Changing and altering ranges of x and y axis in a line graph in MatplotLib
I have created a line graph in Image 1 while I want to change my x-axis which is the 365 days of a year to 12 months but need to plot values of each date. I want to develop a graph like 2.
My Dataframe looks like this
Month Date max min
0 1.0 1900-01-01 15.6 -16.0
1 1.0 1900-01-02 13.9 -26.7
2 1.0 1900-01-03 13.3 -26.7
3 1.0 1900-01-04 10.6 -26.1
4 1.0 1900-01-05 12.8 -15.5
2 Answers
2
Without the code and a try, we can't provide you with a fix.
However, using MatplotLib, the function you are looking for is:
An example that should help you provided by the documentation:
xticks(np.arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue'))
# np.arange(5) is the location, i.e. 0, 1, 2, 3, 4
# ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') are the labels
EDIT: since you're dataframe stores data, you can make a dictionnary to convert number to month:
month = {1: "January", 2: "February", ..., 12: "December"}
Use resampling for this purpose, do a:
df=df.resample("M").last() # M stands for monoth, you can do w for weeks etc
#also .last() will take the last entry of the month
instead of .last() you can also use number of other ways as well, like .min() .max() .mean() etc which will take the values accordingly
documentation is here
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
use resample documentation in the link pandas.pydata.org/pandas-docs/stable/generated/…
– Inder
Jul 3 at 8:06