如何根据其排序值绘制单列

时间:2019-03-22 08:23:58

标签: python dataframe matplotlib

假设我有一个只有一列的数据框。 我对它进行了排序,当我尝试绘制排序后的值时,该图是按照索引而不是排序后的值来绘制的。

如何获得基于排序值绘制的图?

我希望该图是从顶部到底部的曲线。

Ex代码:

import pandas as pd
import matplotlib.pyplot as plt
a=pd.DataFrame()
a['col']=(4,5,8,10,1,0,15,20)
a_sorted=a.sort_values(by='col',ascending=False)
plt.plot(a_s)

1 个答案:

答案 0 :(得分:0)

我相信您需要Series.reset_indexint VideoDecoder::get_next_frame(cv::Mat& mat) { int ret = 0; bool got_frame = false; while (!got_frame && av_read_frame(_p_fmt_ctx, _p_packet) >= 0) { if (_p_packet->stream_index == _video_stream_index) { ret = avcodec_send_packet(_p_dec_ctx, _p_packet); if (ret < 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { break; } while (ret >= 0) { ret = avcodec_receive_frame(_p_dec_ctx, _p_frame); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { break; } sws_scale(_p_img_convert_ctx, _p_frame->data, _p_frame->linesize, 0, _p_dec_ctx->height, _p_frame_rgb->data, _p_frame_rgb->linesize); mat = cv::Mat(_p_frame->height, _p_frame->width, CV_8UC3, _p_frame_rgb->data[0]); got_frame = true; } } av_packet_unref(_p_packet); } if (got_frame) { return _p_dec_ctx->frame_number; } return 0; } 参数的默认索引:

drop=True

然后也可以运行Series.plot

a_sorted=a.sort_values(by='col',ascending=False).reset_index(drop=True)

另一种解决方案是通过Series.values绘制numpy 1d数组:

a_sorted.plot()

或使用sorting in descending order

a_sorted=a.sort_values(by='col',ascending=False)
plt.plot(a_sorted.values)