如何以更准确的方式绘制图形? [英] How to plot the graph in more accurate way?

查看:68
本文介绍了如何以更准确的方式绘制图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由1440 rows × 297 columns组成的数据集.我试图根据时间(X轴)和密度(Y轴)绘制03_jan_2018,但是我遇到了一个问题.结果图不够清晰,也没有出现X轴!!

I have a data set that consists of 1440 rows × 297 columns. I tried to plot 03_jan_2018 in terms of Time(X-Axis) and Density (Y-Axis), but I'm faced with a problem. The outcome graph is not enough clear and also the X-Axis is not appeared!!

我想制作类似的东西:

但是我最后要说的是:

有人可以帮助我吗?

提前谢谢!

推荐答案

x轴已出现,但似乎您面临与

The x-axis has appeared, but it seems that you're facing the same problem as described here. Anyway, I'll show you how you can get what you want and also avoid possible problems with the x-axis notations.

情节1:

代码1:

# imports
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# random data or other data sources
np.random.seed(123)
rows = 1440
df = pd.DataFrame(np.random.uniform(-1,1,size=(rows, 2)),
                  index=pd.date_range('1/1/2000', periods=1440),
                    columns=list('AB'))

df['A'] = df['A'].cumsum()
df['B'] = df['B'].cumsum()

# Plot
fig, ax = plt.subplots()
t = df.index
ax.plot(t, df['A'])
ax.plot(t, df['B'], color='red')

您还可以像这样编辑和调整轴符号:

You can also edit and adjust the axis notations like this:

图2:

代码2:

# imports
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# random data or other data sources
np.random.seed(123)
rows = 1440
df = pd.DataFrame(np.random.uniform(-1,1,size=(rows, 2)),
                  index=pd.date_range('1/1/2020', periods=1440),
                    columns=list('AB'))

df['A'] = df['A'].cumsum()
df['B'] = df['B'].cumsum()

# Make a list of empty myLabels
myLabels = ['']*len(df.index)

# Plot
fig, ax = plt.subplots()
t = df.index
ax.plot(t, df['A'])
ax.plot(t, df['B'], color='red')

# Set labels on every Nth element in myLabels specified by the interval variable
myLabels = ['']*len(df.index)
interval = 2
myLabels[::interval] = [item.strftime('%Y - %m - %d') for item in df.index[::interval]]
ax.xaxis.set_major_formatter(ticker.FixedFormatter(myLabels))
plt.gcf().autofmt_xdate()

# Tilt the labels
plt.setp(ax.get_xticklabels(), rotation=30, fontsize=10)
plt.show()

这篇关于如何以更准确的方式绘制图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆