[英]Matplotlib graphics problems in python
I have the following graphic generated with the following code我使用以下代码生成了以下图形
I want to correct the x-axis display to make the date more readable.我想更正 x 轴显示以使日期更具可读性。 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()
To make the x-tick labels more readable, try rotating them.要使 x-tick 标签更具可读性,请尝试旋转它们。 So use, for example, a 90 degree rotation.
例如,使用 90 度旋转。
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))
I am fairly sure that this can be done by using the window itself of Matplotlib.我相当确定这可以通过使用 Matplotlib 本身的 window 来完成。 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.
要使 x-tick 标签更具可读性,您只需单击右上角的展开按钮或使用 Sheldore 的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.