Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axis: add support for image labels #4503

Closed
Liwr9537 opened this issue Nov 13, 2024 · 5 comments · Fixed by #4517
Closed

Axis: add support for image labels #4503

Liwr9537 opened this issue Nov 13, 2024 · 5 comments · Fixed by #4517

Comments

@Liwr9537
Copy link

Recently, I am using scottplot for scientific drawing. When I need to set the unit for the label and legend, I have to use superscript and subscript. I know that some special unicode can be used. But if the content is more complicated, I have no idea what to do. Besides, I need to add some Latex formula into the plot. For example, I want to add -x^{-rho} into the plot.
So, I want to know if there are some ways for me to do so? Will scottplot add this kind of function in the future?

ScottPlot Version: 5.0.43.0

@bforl
Copy link
Contributor

bforl commented Nov 13, 2024

I don't have a direct answer for you I'm afraid.

But as work around, could you render the latex to a bitmap and display that? (assuming its not constantly changing)

@Liwr9537
Copy link
Author

Do you mean that I can turn the latex into the graph and use this graph as the label text or legend? It seams OK in scottplot4, but I do not find this kind of method in scottplot5.

@swharden
Copy link
Member

Note that superscript and subscript numbers are possible now using unicode:

formsPlot1.Plot.YLabel("PSI²");
formsPlot1.Plot.XLabel("H₂CO₃");

Do you mean that I can turn the latex into the graph and use this graph as the label text or legend?

This should work, but I don't recall whether images are supported in the common places (axis labels, legend items, etc.). I'll modify this issue to track adding (or documenting) how this may be achieved.

Related:

@swharden swharden changed the title How to use subscript or superscript in Scottplot5? Axis: add support for image labels Nov 13, 2024
@swharden
Copy link
Member

I'm merging #4517 now and this feature will be available in the next release!

If you use a third party package to render rich text as a bitmap, you can consume it with ScottPlot and display it anywhere a label is typically displayed

myPlot.Add.Signal(Generate.Sin(51));
myPlot.Add.Signal(Generate.Cos(51));

// This array holds the bytes of a bitmap. Here it's generated,
// but it could be a byte array read from a bitmap file on disk.
byte[] bytes1 = SampleImages.NoisyText("Horiz", 150, 50).GetImageBytes();
byte[] bytes2 = SampleImages.NoisyText("Vert", 150, 50).GetImageBytes();

// Create a ScottPlot.Image from the bitmap bytes
ScottPlot.Image img1 = new(bytes1);
ScottPlot.Image img2 = new(bytes2);

// Display the image for the bottom axis label
myPlot.Axes.Bottom.Label.Image = img1;
myPlot.Axes.Left.Label.Image = img2;

image

@King-Taz
Copy link

King-Taz commented Jan 14, 2025

Note that superscript and subscript numbers are possible now using unicode:

formsPlot1.Plot.YLabel("PSI²");
formsPlot1.Plot.XLabel("H₂CO₃");

While I can get a capital omega as a label, unicode doesn't work in general in Maui. I would appreciate knowing how to get this to work though.

image

Using this code

            var dl1 = MauiPlot1.Plot.Add.Text("  H₂CO₃  ", arrow1Tip);

As a (funny) sidenote, ChatGPT thinks ScottPlot supports Latex formatted labels. I suspect that's an hallucination from the above discussion 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants