question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to show scalars as categories with a scalar bar (and how to move labels of an axis to the other side)

See original GitHub issue

Two issues here related to the following plot:

image

Here is the code I used to plot the figure:

import numpy as np
from vedo import TetMesh, show, screenshot, settings, Picture, buildLUT, Box, \
    Plotter

import time as tm

settings.defaultFont = 'Kanopus'
# settings.useParallelProjection = True # avoid perspective parallax

tet = TetMesh('final_mesh.1.vtk')
# Clone the TetMesh object and threshold it to get the conducotrs
conductor = tet.clone().threshold(name='cell_scalars', above=0, below=4)
cond = conductor.tomesh().lineWidth(2).lineColor([7, 15, 190])

tet.threshold(name='cell_scalars', above=0, below=15)
msh = tet.tomesh().lineWidth(2).lineColor([7, 15, 190])

# Crop the entire mesh
bounds = [503500, 505000, 6414000, 6417000, -1830, 600]
msh.crop(bounds=bounds)

# Crop the conductor mesh
bounds = [503500, 505200, 6414000, 6417000, -1830, 600]
cond.crop(bounds=bounds)

# We need to build a look up table for our color bar
lut = buildLUT([
    (0.0, 'k'),
    (1.0, 'cyan'),
    (2.0, 'skyeblue'),
    (3.0, 'dodgerblue'),
    (4.0, 'blue'),
    (5.0, 'gray'),
    (6.0, 'yellow'),
    (7.0, 'gold'),
    (9.0, 'red'),
    (11.0, 'powderblue'),
    (13.0, 'lime'),
    (15.0, 'seagreen'),
]
)

msh.cmap(lut, 'cell_scalars', on='cells')
# msh.cmap("coolwarm", 'cell_scalars', on='cells')
msh.addScalarBar3D(
    pos=(505800, 6415500, -1830),
    title='Units',
    titleSize=1.5,
    sx=100,
    sy=2000,
    # titleXOffset=,
)
# Create cmap for cond
cond.cmap(lut, 'cell_scalars', on='cells')

axes_opt = dict(
    xtitle='Easting (m)',
    ytitle='Northing (m)',
    ztitle='Elevation (m)',
    xLabelSize=0.015,
    xTitlePosition=0.65,
    yTitlePosition=0.65,
    zTitlePosition=0.65,
    axesLineWidth=4,
    # xrange=msh.xbounds(),
    yrange=msh.ybounds(),
    # zInverted=True,
    xTitleOffset=0.1,
    # zTitleOffset=0.5,
    yzShift=1,
    tipSize=0.,
    # yLabelOffset=0.5,
)

# Set the camera position
plt = Plotter()
plt.camera.SetPosition( [510267.33, 6408661.841, 5262.764] )
plt.camera.SetFocalPoint( [504361.406, 6415247.796, -650.844] )
plt.camera.SetViewUp( [-0.397, 0.39, 0.831] )
plt.camera.SetDistance( 10640.747 )
plt.camera.SetClippingRange( [6131.035, 16343.212] )

size = [3940, 2160]
show(msh, cond, axes=axes_opt, size=size, interactive=True, zoom=1.2)
screenshot('model_mesh_vedo.png')
# npimg = screenshot(returnNumpy=True)
# pic = Picture(npimg)
# pic.crop(left=0.2, right=0.2, top=0.01, bottom=0.01).write('src_obs_refinement_vedo.png')

# from wand import image

# with image.Image(filename='src_obs_refinement_vedo.png') as imag:
#     imag.trim(color=None, fuzz=0)
#     imag.save(filename='src_obs_refinement_vedo_trim.png')
  1. How to show scalar values as categories in the scalar bar. Right now only values are shown. In Paraview, I can show scalars as categories and it seems that I can probably also do that using PyVista.
  2. The 3D axes. The yz axes used to be located at the left of the figure (default) behaviour, but that causes the z-title to be not readable (reversed, something like the below picture). Then, I had to move it to the right side. However, the titles are not moving together with the axes (both the y- and z-axis titles). Also, the labels of the y-axis is located at the left of the axis and seems to be buried under the mesh. I want to simply move them to the right of the axis. So, how to do all of these changes? image

The vtk file used to plot the figure: final_mesh.1.vtk.zip

Thanks in advance for any comments and suggestions!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
XushanLucommented, Aug 17, 2021

The manuscript I mentioned earlier that uses vedo has been accepted for publish. I have finished proofreading and the journal should be able to put the final version up on their website soonish. But here is a link to the paper on the journal’s website as of now: https://library.seg.org/doi/10.1190/geo2020-0657.1

I might remember to update the link after the final version appears on the website. The paper cited vedo and acknowledged your help in the end. Once again, thanks for making vedo available to us and for all the help you provided along the way. Hopefully, more people from the geophysics community could see the potential of what vedo can do in plotting all the Earth models when they read my paper.

1reaction
marcomusycommented, May 2, 2021

yes: pip install -U git+https://github.com/marcomusy/vedo.git is sufficient to install the dev version. I just pushed it to gihub so you need to redo the pip command above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change axis labels in a chart
Right-click the category labels you want to change, and click Select Data. Right-click the category axis and Select Data. In the Horizontal (Category)...
Read more >
2.1 Scalars and Vectors | University Physics Volume 1
Describe the difference between vector and scalar quantities. Identify the magnitude and direction of a vector. Explain the effect of multiplying a vector ......
Read more >
matplotlib.axes.Axes.plot — Matplotlib 3.6.2 documentation
The coordinates of the points or line nodes are given by x, y. The optional parameter fmt is a convenient way for defining...
Read more >
TensorBoard Tutorial: Run Examples & Use Logdir
Scalars - Visualize scalar values, such as classification accuracy. ... On the other hand, things can go wrong even when you are quite...
Read more >
How to Change Horizontal Axis Labels in Excel - YouTube
... appear as a sequence of numbers (one through to x), then it is probably because Excel has interpreted your category labels as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found