最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to plot a processing message in power Bi visual - Stack Overflow

programmeradmin0浏览0评论

I'm developing a visual using Python within Power BI, but due to the large dataset size, processing takes some time.

How can I display a message or a loading symbol to inform users that the graph is temporarily blank because the Python script is still running? I attempted using the print statement within the figure environment, but it wasn't effective:

import matplotlib.dates as mdates
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.seasonal import seasonal_decompose

# Assign the provided dataset to a dataframe
df = dataset

# Convert the 'Date' column to datetime, using a general format to handle inconsistencies
df['feature1'] = pd.to_datetime(df['feature2'], errors='coerce')

# Check for any parsing errors
if df['feature1'].isna().any():
    print("Warning: Some features could not be parsed and are set to NaT.")

# Filter out rows where 'feature1' is NaT, as they won't plot correctly
df = df.dropna(subset=['feature1'])

# Create the plot
fig, ax1 = plt.subplots(figsize=(10.0, 7.0))
print("Processing Data...")
ax1.scatter(df['feature1'], df['feature3'], linewidth=1.5, color='blue', label='Label 1')

# Set the x-axis limits and format
xmin = df['feature1'].min()
xmax = df['feature1'].max()
ax1.set_xlim(xmin, xmax)
ax1.set_ylim(275, 230)
ax1.invert_yaxis()
ax1.tick_params(axis='x', rotation=45)

# Extract a single value from each array
feature4 = df['feature5'].unique()[0]
feature6 = df['feature7'].unique()[0]
feature8 = df['feature9'].unique()[0]
name = df['feature10'].unique()[0]

# Plot the horizontal lines
ax1.plot([xmin, xmax], [feature4, feature4], color='black', linestyle='--', linewidth=1, alpha=1, label='Label 2')
ax1.plot([xmin, xmax], [feature6, feature6], color='darkgray', linestyle='--', linewidth=1, alpha=1, label='Label 3')
ax1.plot([xmin, xmax], [feature8, feature8], color='orange', linestyle='--', linewidth=1, alpha=1, label='Label 4')

# Set the x and y-axis labels and title
ax1.set_xlabel('Feature X')
ax1.set_ylabel('Feature Y')
ax1.set_title('Plot Title {}'.format(name))
plt.tight_layout()
ax1.legend()
plt.show()

Any guidance on how to implement a loading message until the data processing completes and the final graph is generated would be greatly appreciated. Thank you!

发布评论

评论列表(0)

  1. 暂无评论