1

I have the following graphic generated with the following code

enter image description here

I want to correct the x-axis display to make the date more readable. I would also like to be able to enlarge the graph

My code is :

import requests
import urllib.parse
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

def get_api_call(ids, **kwargs):
    API_BASE_URL = "https://apis.datos.gob.ar/series/api/"
    kwargs["ids"] = ",".join(ids)
    return "{}{}?{}".format(API_BASE_URL, "series", urllib.parse.urlencode(kwargs))


df = pd.read_csv(get_api_call(
    ["168.1_T_CAMBIOR_D_0_0_26", "101.1_I2NG_2016_M_22", 
    "116.3_TCRMA_0_M_36", "143.3_NO_PR_2004_A_21", "11.3_VMATC_2004_M_12"],
    format="csv", start_date=2018
))

time = df.indice_tiempo
construccion=df.construccion
emae = df.emae_original
time = pd.to_datetime(time)

list = d = {'date':time,'const':construccion,'EMAE':emae} 

dataset = pd.DataFrame(list)

plt.plot( 'date', 'EMAE', data=dataset, marker='o', markerfacecolor='blue', markersize=12, color='skyblue', linewidth=4)
plt.plot( 'date', 'const', data=dataset, marker='', color='olive', linewidth=2)
plt.legend()

2 Answers 2

4

To make the x-tick labels more readable, try rotating them. So use, for example, a 90 degree rotation.

plt.xticks(rotation=90)

To enlarge the size, you can define your own size using the following in the beginning for instance

fig, ax = plt.subplots(figsize=(10, 8))
Sign up to request clarification or add additional context in comments.

2 Comments

Better than the answer I was going to post. Didn't know this was possible +1
I would like enlarge the graph, How can I do it ?
1

I am fairly sure that this can be done by using the window itself of Matplotlib. If you have the latest version you can enlarge on a section of the graph by clicking the zoom button in the bottom left. To get the x-tick labels to be more readable you can simply click the expand button in the top right or use Sheldore's solution.

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.