简体   繁体   English

我该如何用文字确定范围并使其在图的y轴上

[英]how can I make range with text and make this to y-axis in plot

I have two questions! 我有两个问题!

Q1. Q1。 first I want to make a list like 首先,我想列出一个清单

df.CellNo = [Cell1,Cell2,Cell3,...,Cell96]

so I tried df.CellNo = ['CellNo'] + range(1,97) but it was not working. 所以我尝试了df.CellNo = ['CellNo'] + range(1,97)但是它不起作用。

so I did a code like behind. 所以我做了像后面的代码。

df = pd.DataFrame({'CellNo': range(1,97)})
df.CellNo = df.CellNo.astype(str)
df.CellNo = 'Cell' + df.CellNo

Is there any easier way to do this?? 有没有更简单的方法可以做到这一点? (in short way) (简而言之)

Q2. Q2。 second I want to plot with x-axis is 'Time' data and y-axis is df.CellNo data when I just plot df 第二个我想用x轴绘制的是'时间'数据,而y轴是df。

two muppets I want to make y-axis sorted by nuber like Cell5, Cell6, Cell7, Cell10, Cell11 ... from behind. 我想从后面按像Cell5,Cell6,Cell7,Cell10,Cell11 ...这样的nuber对y轴进行排序。 how can I do,, 我能怎么做,,

IIUC, this is about sorting dataframe by substring. IIUC,这是关于按子字符串对数据帧进行排序。

You can make a key column and then sort the dataframe: 您可以创建一个关键列,然后对数据框进行排序:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({'Time' : [20190721,20190722,20190723], 'No':['A90','A5','A10']})
df['key'] = df['No'].str.extract('(\d+)').astype(int)
df.sort_values('key', inplace=True)
plt.scatter(df.Time,df.No)

Output: 输出:

在此处输入图片说明

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

相关问题 如何在 Python 中制作具有两个不同 Y 轴的 Plot - How to Make a Plot with Two Different Y-axis in Python python - 如何在x轴上的值范围上制作条形图并计算y轴上的范围? - How to make a bar chart on range of values on x-axis and count on the range on y-axis in python? 为什么不能在Pandas系列生成的绘图上设置y轴范围? - Why can't I set the y-axis range on a plot produced from a Pandas Series? 在matplotlib中使用2个不同的y轴时,如何制作平方图? - How to make a squared plot when using 2 different y-axis in matplotlib? 如何制作一维图,其中值由颜色表示,而不是在 y 轴上? - How to make 1-dimensional plot, where values are represented by colors, not on y-axis? 如何在 python 中以像素数为 x 轴,灰度颜色为 y 轴 plot 图形? - How can I plot the figure with the number of pixel as a x-axis and the grayscale color as a y-axis in python? Dash/Plotly:如何使用相同的 x 轴在 y 轴上绘制两列? - Dash/Plotly: How can I plot two columns on the y-axis with the same x axis? 格式化 y 轴刻度文本图 - Formatting y-axis tick text plot 如何使用 seaborn 的条形图 plot 辅助 y 轴? - How can I plot a secondary y-axis with seaborn's barplot? 如何创建具有 3 个不同 y 轴的 Seaborn 线图? - How can I create a Seaborn line plot with 3 different y-axis?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM