Apply style from JSON file to any (valid) histogram

Hello, for once I don’t come asking for help, but rather I want to share to you something that I think could be useful, I call it a “Style Code”.

This is how it works, you have a bunch of ugly histograms, you need to make them pretty, so you open a text editor and you write a JSON file with all the options you want, put that file in the same directory as your histograms, run the Style Code, and violà, you have now pretty histograms.

If then you need to format other histograms, simply go to your JSON file, change it, and run the same code, it will apply the new format.

Now, I haven’t included in the Style Code all the possible options for a histogram, but it’s very modular, so it’s very easy to include new options, and if you follow the protocol, the same Style Code should work with any JSON style file, you could share you JSON file with someone else and even if they Style Code is a little different there should be no problem.

Here is the Style Code style.py (1.5 KB)
This website doesn’t let me upload .json files, so I’ll show you the text, just remember to save it as .json (and with UT-8 just to be safe)

{
	"canvasX": 2000,
	"canvasY": 5000,
	"XSetTitle": "nm",
	"YSetTitle": "Arbitrary Units",
	"XSetRangeUser": 
	[
		350,
		600
	],
	"SetTitle": "Spectrum of the sample",
	"Draw": "bar"
}

As you can see this will create a python dictionary with methods that can be applied to a histogram as keys and how they should be applied as values.

Also, I couldn’t get the color thing working yet, I’ll update you when I can

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.