﻿ osx – 在iPython或iPython Notebook中显示可旋转的3D绘图 - 代码日志

#### osx – 在iPython或iPython Notebook中显示可旋转的3D绘图

(Mac OSX 10.10.5)

``````    # These lines are comments
# Initial setup from an online python notebook tutorial is below.
# Note the first line "%matplotlib inline" this is how the tutorial has it.
# Two solutions 1. use: "%matplotlib notebook" graphs appear dynamic in the notebook.
#               2. use: "%matplotlib" (only) graphs appear dynamic in separate window.
#    ( 2. is the best solution for detailed graphs/plots. )

%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

pd.set_option('html',False)
pd.set_option('max_columns',30)
pd.set_option('max_rows',10)

# What follows is a copy of the 3D plot example code.
# Data is randomly generated so there is no external data import.

def randrange(n, vmin, vmax):
return (vmax-vmin)*np.random.rand(n) + vmin

fig = plt.figure()
n = 100
for c, m, zl, zh in [('r', 'o', -60, -25), ('b', '^', -30, -5)]:
xs = randrange(n, 23, 50)
ys = randrange(n, 0, 100)
zs = randrange(n, zl, zh)
ax.scatter(xs, ys, zs, c=c, marker=m)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()
``````

The tkinter package (“Tk interface”) is the standard Python interface to the Tk GUI toolkit. Both Tk and tkinter are available on most Unix platforms, as well as on Windows systems.