So I have this plot: Plot histogram for mvarreturn histogram(mvarreturn, bins=50,…
- User
So I have this plot:
Plot histogram for m_var_return
histogram(m_var_return, bins=50, alpha=0.7, title="Histogram", xlabel="Portfolio value", label="") histogram!(m_var_return_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!([median_value], color=:green, label="Median")
Plot histogram for m_var_return2
histogram(m_var_return2, bins=50, alpha=0.7, title="Histogram", xlabel="Portfolio value", label="") histogram!(m_var_return2_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!([median_value_var2], color=:green, label="Median")
Plot histogram for rmin_avg_returns
histogram(rmin_avg_returns, bins=50, alpha=0.7, title="Histogram", xlabel="Portfolio value", label="") histogram!(rmin_avg_returns_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!([median_value_rmin], color=:green, label="Median")
Now. I want to display those 3 plots next to each other. Currently only one is displayed. It is in Julia.
- Assistant
To display three plots next to each other, you can use the
plot()function with thelayoutoption. Firstly, create each of the subplot separately, and then display them together using theplot()function. Here's how to do it in your case:using Plots # Create first histogram plot p1 = histogram(m_var_return, bins=50, alpha=0.7, title="Histogram", xlabel="Portfolio value", label="") histogram!(p1, m_var_return_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p1, [median_value], color=:green, label="Median") # Create second histogram plot p2 = histogram(m_var_return2, bins=50, alpha=0.7, title="Histogram", xlabel="Portfolio value", label="") histogram!(p2, m_var_return2_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p2, [median_value_var2], color=:green, label="Median") # Create third histogram plot p3 = histogram(rmin_avg_returns, bins=50, alpha=0.7, title="Histogram", xlabel="Portfolio value", label="") histogram!(p3, rmin_avg_returns_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p3, [median_value_rmin], color=:green, label="Median") # Display all three plots together plot(p1, p2, p3, layout=(1, 3)) - User
Add common legend, place it on top left, adjust the size=(1200, 600) for final display and add titles for each histogram accordingly: "Strategia i" replacing i with numbers from 1 to 3.
- Assistant
To add a common legend, place it in the top left corner, adjust the size and add individual titles to each histogram. You can modify the previous code snippet like this:
using Plots # Create first histogram plot p1 = histogram(m_var_return, bins=50, alpha=0.7, title="Strategia 1", xlabel="Portfolio value", label="", legend=:topleft) histogram!(p1, m_var_return_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p1, [median_value], color=:green, label="Median") # Create second histogram plot p2 = histogram(m_var_return2, bins=50, alpha=0.7, title="Strategia 2", xlabel="Portfolio value", label="", legend=false) histogram!(p2, m_var_return2_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p2, [median_value_var2], color=:green, label="Median") # Create third histogram plot p3 = histogram(rmin_avg_returns, bins=50, alpha=0.7, title="Strategia 3", xlabel="Portfolio value", label="", legend=false) histogram!(p3, rmin_avg_returns_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p3, [median_value_rmin], color=:green, label="Median") # Display all three plots together with adjusted size plot(p1, p2, p3, layout=(1, 3), size=(1200, 600)) - User
So I have adjusted the code: using Plots
Create first histogram plot
p1 = histogram(m_var_return, bins=50, alpha=0.7, title="Strategia 1", xlabel="Portfolio value", label="", legend=:topleft) histogram!(p1, m_var_return_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p1, [median_value], color=:green, label="Median")
Create second histogram plot
p2 = histogram(m_var_return2, bins=50, alpha=0.7, title="Strategia 2", xlabel="Portfolio value", label="", legend=false) histogram!(p2, m_var_return2_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p2, [median_value_var2], color=:green, label="Median")
Create third histogram plot
p3 = histogram(rmin_avg_returns, bins=50, alpha=0.7, title="Strategia 3", xlabel="Portfolio value", label="", legend=false) histogram!(p3, rmin_avg_returns_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p3, [median_value_rmin], color=:green, label="Median")
Display all three plots together with adjusted size
plot(p1, p2, p3, layout=(1, 3), size=(1500, 1000))
Now. Use the same scale for each plot on X and Y axis. (X is from around 50 to around 180 and y from 0 to 120).
- Assistant
To use the same scale for the X and Y axes on all plots, you can add the
xlimsandylimsoptions to each subplot. Here's the modified code:using Plots # Set the common limits x_limits = (50, 180) y_limits = (0, 120) # Create first histogram plot p1 = histogram(m_var_return, bins=50, alpha=0.7, title="Strategia 1", xlabel="Portfolio value", xlims=x_limits, ylims=y_limits, label="", legend=:topleft) histogram!(p1, m_var_return_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p1, [median_value], color=:green, label="Median") # Create second histogram plot p2 = histogram(m_var_return2, bins=50, alpha=0.7, title="Strategia 2", xlabel="Portfolio value", xlims=x_limits, ylims=y_limits, label="", legend=false) histogram!(p2, m_var_return2_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p2, [median_value_var2], color=:green, label="Median") # Create third histogram plot p3 = histogram(rmin_avg_returns, bins=50, alpha=0.7, title="Strategia 3", xlabel="Portfolio value", xlims=x_limits, ylims=y_limits, label="", legend=false) histogram!(p3, rmin_avg_returns_5quantile, color=:red, bins=10, label="Value at Risk 5%") vline!(p3, [median_value_rmin], color=:green, label="Median") # Display all three plots together with adjusted size plot(p1, p2, p3, layout=(1, 3), size=(1500, 1000))