简体   繁体   English

Pandas/matplotlib 线图不显示 x 轴文本标签

[英]Pandas/matplotlib line plot does not show x axis text labels

Issue问题

Plotting data from a DataFrame into a line plot excludes "dates" on the x axis.将 DataFrame 中的数据绘制到线图中不包括 x 轴上的“日期”。

north_result = list(data.aggregate(pipeline))

dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
north_result_df.plot.line()

在此处输入图片说明

Line plot requires dates just above 'months' on the x axis.线图需要 x 轴上“月”正上方的日期。 Dates show if they are numeric and not strings...any help would be greatly appreciated!日期显示它们是否是数字而不是字符串......任何帮助将不胜感激! As you can tell i am pretty new to Pandas...正如你所知道的,我对 Pandas 还很陌生......

Solution解决方案

north_result = list(data.aggregate(pipeline))

dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
plt.plot(north_result_df.index, north_result_df["total"])
plt.show()

you can use pyplot你可以使用 pyplot

import matplotlib.pyplot as plt
north_result =[5,6,7,2,8,5,4,8,9,4,1,5]
dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
plt.plot(north_result_df)
plt.show()

the result will be like:结果将是这样的:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用来自 csv 的 matplotlib 和 pandas 的 Python 图表不显示所有 x 轴标签 - Python chart using matplotlib and pandas from csv does not show all x-axis labels 在matplotlib中从pandas系列制作线图时显示分类x轴值 - Show categorical x-axis values when making line plot from pandas Series in matplotlib 将Matplotlib(线图)与Pandas数据帧中的数据一起使用时,沿x轴缺少文本标签 - Missing textual labels along x-axis when using Matplotlib (line-plot) with data from a Pandas dataframe 旋转Matplotlib寄生图中的x轴标签 - Rotate x axis labels in Matplotlib parasite plot 在 matplotlib 中使用两个 y 轴格式化 x 轴标签(条形图和折线图) - formatting x-axis labels with two y-axis in matplotlib (bar and line plot) 熊猫图x轴标签重叠 - pandas plot x axis labels overlapping 折线图中的中心x轴标签 - Center x-axis labels in line plot Jupyter Matplotlib图不响应设置xlim或对x轴标签的修改 - Jupyter matplotlib plot does not respond to setting xlim or to modifications to x-axis labels 如何使用 Pandas/Matplotlib 将 plot X 轴上的日期、Y 轴上的时间和 HH:MM 格式的当前时间作为刻度标签? - How to plot Date in X Axis, Time in Y axis with Pandas/Matplotlib and present time in HH:MM format as tick labels? 无法在matplotlib x轴上显示熊猫dateindex - Unable to show Pandas dateindex on a matplotlib x axis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM