我有以下脚本可以绘制图形:
x = np.array([0,1,2])
y = np.array([5, 4.31, 4.01])
plt.plot(x, y)
plt.show()
问题是,直线从一点到另一点都是笔直的,但是我想平滑点之间的直线。
如果我使用scipy.interpolate.spline平滑数据,则会得到以下结果:
order = np.array([0,1,2])
y = np.array([5, 4.31, 4.01])
xnew = np.linspace(order.min(), order.max(), 300)
smooth = spline(order, y, xnew)
plt.plot(xnew, smooth)
plt.show()
但是我希望得到与给定example相同的结果
答案 0 :(得分:1)
如果使用的点数多于3,您将得到与链接的问题相同的结果。阶数为3的样条有很多方法可以通过3个点。
但是您当然可以将阶数减少到2。
public class CreateSpreadSheetTask extends AsyncTask<Void, Void, Void> {
private com.google.api.services.sheets.v4.Sheets mService = null;
private Exception mLastError = null;
private String title = null;
private CreateSpreadsheetListener listener = null;
public CreateSpreadSheetTask(GoogleAccountCredential credential, String title, CreateSpreadsheetListener listener) {
HttpTransport transport = AndroidHttp.newCompatibleTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
mService = new Sheets.Builder(
transport, jsonFactory, credential)
.setApplicationName("Google Sheets API Android Quickstart")
.build();
this.title = title;
this.listener = listener;
}
@Override
protected Void doInBackground(Void... params) {
try {
this.listener.onRecvCreateSpreadsheet(getSpreadsheetFromApi());
} catch (Exception e) {
e.printStackTrace();
mLastError = e;
cancel(true);
}
return null;
}
private Spreadsheet getSpreadsheetFromApi() throws IOException {
Spreadsheet spreadsheet = new Spreadsheet();
SpreadsheetProperties properties = new SpreadsheetProperties();
properties.setTitle(this.title);
spreadsheet.setProperties(properties);
Sheets.Spreadsheets.Create request = mService.spreadsheets().create(spreadsheet);
return request.execute();
}
}