kev
kev

Reputation: 139

Matplotlib graphics problems in python

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()

Upvotes: 1

Views: 88

Answers (2)

Sheldore
Sheldore

Reputation: 39062

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))

Upvotes: 4

Fateh A.
Fateh A.

Reputation: 372

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.

Upvotes: 1

Related Questions