Чтобы построить график с использованием индекса в качестве оси X в pandas, вы можете использовать различные методы. Вот несколько примеров кода:
-
Линейный график:
import pandas as pd import matplotlib.pyplot as plt # Create a DataFrame data = {'Value': [10, 15, 7, 12, 9]} df = pd.DataFrame(data) # Plot using the index as x df.plot(y='Value', use_index=True, kind='line') # Set the plot title and labels plt.title('Line Plot with Index as X') plt.xlabel('Index') plt.ylabel('Value') # Display the plot plt.show() -
Гистограмма:
import pandas as pd import matplotlib.pyplot as plt # Create a DataFrame data = {'Value': [10, 15, 7, 12, 9]} df = pd.DataFrame(data) # Plot using the index as x df.plot(y='Value', use_index=True, kind='bar') # Set the plot title and labels plt.title('Bar Plot with Index as X') plt.xlabel('Index') plt.ylabel('Value') # Display the plot plt.show() -
Участок площади:
import pandas as pd import matplotlib.pyplot as plt # Create a DataFrame data = {'Value': [10, 15, 7, 12, 9]} df = pd.DataFrame(data) # Plot using the index as x df.plot(y='Value', use_index=True, kind='area') # Set the plot title and labels plt.title('Area Plot with Index as X') plt.xlabel('Index') plt.ylabel('Value') # Display the plot plt.show() -
Диаграмма рассеяния:
import pandas as pd import matplotlib.pyplot as plt # Create a DataFrame data = {'Value': [10, 15, 7, 12, 9]} df = pd.DataFrame(data) # Plot using the index as x df.plot(y='Value', use_index=True, kind='scatter') # Set the plot title and labels plt.title('Scatter Plot with Index as X') plt.xlabel('Index') plt.ylabel('Value') # Display the plot plt.show()
Это всего лишь несколько примеров того, как вы можете использовать индекс в качестве оси X при построении графиков с помощью панд. Вы можете изучить дополнительные типы графиков и параметры настройки в соответствии с вашими конкретными требованиями.