I have been trying to execute following Python code (graphcreater.py) using C# Visual Studio. I added IronPyton 2.7.7 and IronPython.StdLib 2.7.7 via NuGet package manager.
Once I run the program it gives an exception saying that,
No module named mpl_toolkits.mplot3d
I need to figure out how to import mpl_toolkits module in Python code (graphcreater.py) correctly.
NOTE: The graphcreater.py is running when executed using Python only.
Python Code (graphcreater.py):
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
fig = plt.figure()
xs = np.array([ 0,1,2,2,1,1,0]);
ys = np.array([ 0,0,0,2,2,3,3]);
zs = np.array([3 ,0, -1, 6, 2, 1,4]);
ax=fig.add_subplot(1,1,1, projection='3d')
ax.grid(True)
ax.plot_trisurf(xs, ys, zs,cmap=cm.coolwarm,linewidth=0.2, antialiased=True)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
# Add a color bar which maps values to colors
# fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
C# Code :
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace graphCreator
{
class Program
{
static void Main(string[] args)
{
ScriptEngine engine = Python.CreateEngine();
engine.ExecuteFile(@"graphcreater.py");
}
}
}