Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import matplotlib.pyplot as plt | |
| # Mock individual demand curves for mahi mahi tuna (price decreases as quantity increases) | |
| individuals = ["Mary", "Bob", "Jim"] | |
| # Define quantity points (e.g., pounds) | |
| quantities = [1, 2, 3, 4, 5] | |
| # Prices per unit (downward-sloping demand) | |
| market_demand = { | |
| "Mary": [25, 22, 18, 15, 10], | |
| "Bob": [24, 21, 17, 14, 9], | |
| "Jim": [26, 23, 19, 16, 11] | |
| } | |
| # Non-market (fish diversity) WTP stays as before (quality on X-axis) | |
| nonmarket_levels = ["Low", "Medium", "High"] | |
| nonmarket_wtp = { | |
| "Mary": [10, 18, 23], | |
| "Bob": [12, 16, 28], | |
| "Jim": [10, 10, 10] | |
| } | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| # Define quantity range (0 to 15) | |
| quantities = np.linspace(0, 15, 100) | |
| import gradio as gr | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| def plot_market_demand(): | |
| quantities = np.linspace(0, 15, 100) | |
| mary_prices = 30 - 1.5 * quantities | |
| bob_prices = 25 - 1.2 * quantities | |
| jim_prices = 35 - 2.0 * quantities | |
| fig, ax = plt.subplots(figsize=(6, 4)) | |
| ax.plot(quantities, mary_prices, label="Mary") | |
| ax.plot(quantities, bob_prices, label="Bob") | |
| ax.plot(quantities, jim_prices, label="Jim") | |
| ax.set_xlabel("Quantity (Q)") | |
| ax.set_ylabel("Price (P)") | |
| ax.set_title("Individual Demand Curves") | |
| ax.legend() | |
| ax.grid(True) | |
| ax.set_xlim(0, 15) | |
| ax.set_ylim(0, 40) | |
| return fig | |
| def plot_nonmarket_wtp(): | |
| fig, ax = plt.subplots() | |
| for name in individuals: | |
| ax.plot(nonmarket_levels, nonmarket_wtp[name], marker='o', label=name) | |
| ax.set_title("Non-Market WTP: Fish Diversity") | |
| ax.set_xlabel("Quality Level") | |
| ax.set_ylabel("WTP ($)") | |
| # Force axes to start at zero | |
| ax.set_xlim(left=0) | |
| ax.set_ylim(bottom=0) | |
| ax.legend() | |
| plt.tight_layout() | |
| return fig | |
| def app(): | |
| market_fig = plot_market_demand() | |
| nonmarket_fig = plot_nonmarket_wtp() | |
| return market_fig, nonmarket_fig | |
| demo = gr.Interface( | |
| fn=app, | |
| inputs=[], | |
| outputs=[gr.Plot(label="Market Demand"), gr.Plot(label="Non-Market WTP")], | |
| title="WTP and Demand Visualization App", | |
| description="Shows individual demand curves for market goods (e.g., mahi mahi tuna) and WTP curves for non-market goods (e.g., fish diversity)." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |