plot_extra_yaxis.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """Add a secondary y-axis for units conversion"""
  2. from vedo import np, settings, dataurl, Mesh, show
  3. from vedo.pyplot import plot, Figure
  4. settings.annotated_cube_texts = ['front','back','left','right','top','bttm']
  5. x0, x1 = [0.3, 2.0]
  6. x = np.linspace(x0, x1, num=50)
  7. # The main plot
  8. fig1 = plot(
  9. x,
  10. 1000*np.cos(x+1),
  11. xlim=[x0, x1],
  12. ylim=[-1000, 250],
  13. aspect=16/9,
  14. padding=0, # do not mess up with margins
  15. title="Wing pull vs position",
  16. xtitle="Distance from airplane axis [m]",
  17. ytitle="N [Kg*m/s^2 ]",
  18. axes=dict(
  19. xygrid_transparent=False,
  20. xygrid_color='k7',
  21. xyalpha=1,
  22. xyplane_color='w',
  23. yhighlight_zero=True,
  24. ),
  25. )
  26. # fig1copy = fig1.clone2d("bottom-right") # can make it 2d (on screen)
  27. # This empty Figure just creates a new y-axis in red
  28. fig2 = Figure(
  29. fig1.xlim, # same as fig1
  30. fig1.ylim * 7.236, # units conversion factor
  31. aspect=fig1.aspect, # same as fig1
  32. padding=fig1.padding, # same as fig1
  33. xtitle='', # don't draw the x-axis!
  34. ytitle='Poundal [lb*ft/s^2 ]',
  35. axes=dict( # extra options for y-axis
  36. number_of_divisions=10,
  37. yshift_along_x=1, # shift 100% to the right
  38. ylabel_offset=-1,
  39. ylabel_justify="center-left",
  40. ytitle_position=0.5,
  41. ytitle_justify="top-center",
  42. axes_linewidth=3,
  43. c='red3',
  44. ),
  45. )
  46. fig1.rotate_x(90).rotate_z(90).shift(-0.5, 0, 1)
  47. fig2.rotate_x(90).rotate_z(90).shift(-0.5, 0, 1)
  48. msh = Mesh(dataurl+"cessna.vtk")
  49. cam = dict( # press C to get these values
  50. pos=(3.899, -0.4781, 1.157),
  51. focal_point=(-0.1324, 0.9041, 0.3530),
  52. viewup=(-0.1725, 0.06857, 0.9826),
  53. )
  54. show(msh, fig1, fig2, __doc__,
  55. axes=5, camera=cam, bg2='lb').close()