File:Rosenbrock3.gif

From testwiki
Jump to navigation Jump to search
Rosenbrock3.gif (600 × 400 pixels, file size: 1.14 MB, MIME type: image/gif, looped, 41 frames, 8.2 s)

This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

Summary

Description
English: Animation of Rosenbrock's function of three variables.
Date
Source Own work
Author nicoguaro
GIF development
InfoField
 This plot was created with Matplotlib.
Source code
InfoField

Python code

"""
Animation of the Rosenbrock function of three variables
"""
import numpy as np
from scipy.optimize import rosen
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation

Axes3D
plt.rcParams["font.size"] = 10
plt.rcParams["mathtext.fontset"] = "cm"

x1, x2 = np.mgrid[-2.5:2.5:51j, -2.5:2.5:51j]
x3  = np.linspace(-2.5, 2.5, 21)
x3  = np.append(x3, x3[-2::-1])
fun = rosen([x1, x2, x3[0]])

fig = plt.figure(figsize=(6, 4))
ax = fig.add_subplot(111, projection='3d')
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) 
ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0)) 
ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))

def data_gen(num):
    fun = rosen([x1, x2, x3[num]])
    ax.cla()
    surf = ax.plot_wireframe(x1, x2, fun/1000, linewidth=1, color="#3c3c3c",
                         rstride=51, cstride=51)
    contour = ax.contour(x1, x2, fun/1000, 20)
    ax.set_xlabel(r"$x_1$", fontsize=12)
    ax.set_ylabel(r"$x_2$", fontsize=12)
    ax.set_zlabel(r"$f(x_1, x_2, x_3)/10^3$", fontsize=12)
    ax.set_title(r"$x_3 = {}$".format(x3[num]), fontsize=12, y=1.08)
    ax.set_xlim(-2.5, 2.5)
    ax.set_ylim(-2.5, 2.5)
    ax.set_zlim(0, 16)
    ax.view_init(elev=45, azim=-45)
    return surf, contour

ani = animation.FuncAnimation(fig, data_gen, range(41))
ani.save("rosenbrock3.gif", writer='imagemagick')
plt.show()

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

26 June 2018

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current18:24, 26 June 2018Thumbnail for version as of 18:24, 26 June 2018600 × 400 (1.14 MB)wikimediacommons>NicoguaroImprove lines width

The following page uses this file: