python-2.7 - 如何在大型数据集上优化图形质量
问题描述
我正在尝试优化我使用 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)
结果 :
解决方案
到目前为止尚未讨论的答案是简单地扩展格式文件(例如,生成的 .png 文件的“经典”尺寸是 600x800。例如,可以使用不同的格式plt.rcParams["figure.figsize"] = (80,12)
看到这个帖子
推荐阅读
- c++ - SFML 我的移动功能无法正常工作
- reactjs - fastAPI中的异步心跳
- php - 如何获取两个日期之间的持续时间?(php)
- c - 为 CHECK_FUNCTION_EXIST 添加链接器标志
- python-3.x - 是否可以设置 Pypandoc 以使用与本机 Word 文件相同的纸张大小、对齐方式、表格、颜色等来转换文件?
- c# - Entity Framework 复数 where 条件
- android - 首先在 RecyclerView 外滚动
- javascript - Office.js:使用 Excel.Range 类在 Excel 上添加多行
- excel - 将列总计写入任何位置
- r - 安装 R 包“WRS”