如何在大型数据集上优化图形质量

时间:2019-02-25 10:38:53

标签: python-2.7 matplotlib seaborn

我正在尝试优化使用matplotlib生成的图像质量。 数据集大约+200 000点,即使我放大,我也希望有一些可读性。 基于这篇文章:(1),我尝试生成pdf,png格式的图形,更改了DPI,但每次结果都不如我所料...

我的代码:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import csv
import seaborn as sns


sns.set_style("darkgrid")

x=[]
y=[]

i=1

with open('data_dut_2_2019-2-22-17-34-36.csv', 'r') as csvfile:
    plots= csv.reader(csvfile, delimiter=';')
    next(plots)
    for row in plots:
        y.append(float((row[1]).replace(',','.')))
        x.append(i)

        i+=1


#plt.plot(x,y, marker=',')

f, (ax, ax2) = plt.subplots(2, 1, sharex=True)
ax.plot(x,y,  linewidth=1)
ax2.plot(x,y,  linewidth=1)

# zoom-in / limit the view to different portions of the data
ax.set_ylim(200, 1000)  # outliers only
ax2.set_ylim(0, .12)  # most of the data

# hide the spines between ax and ax2
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax.xaxis.tick_top()
ax.tick_params(labeltop='off')  # don't put tick labels at the top
ax2.xaxis.tick_bottom()

d = .015  # how big to make the diagonal lines in axes coordinates
# arguments to pass to plot, just so we don't keep repeating them
kwargs = dict(transform=ax.transAxes, color='k', clip_on=False)
ax.plot((-d, +d), (-d, +d), **kwargs)        # top-left diagonal
ax.plot((1 - d, 1 + d), (-d, +d), **kwargs)  # top-right diagonal

kwargs.update(transform=ax2.transAxes)  # switch to the bottom axes
ax2.plot((-d, +d), (1 - d, 1 + d), **kwargs)  # bottom-left diagonal
ax2.plot((1 - d, 1 + d), (1 - d, 1 + d), **kwargs)  # bottom-right diagonal


f.suptitle('Data from the CSV File: conso en mA')

plt.xlabel('Date')
plt.ylabel('Conso')

plt.savefig('test_init_0_1.pdf', dpi=1000)

结果:

Result zoom

1 个答案:

答案 0 :(得分:0)

到目前为止,尚未讨论的答案是简单地扩展格式文件(例如,生成的.png文件的“经典”尺寸为600x800。可以使用例如{ {1}}

请参阅this post

相关问题