Message Boards Message Boards

0
|
1463 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Formatting axes/frames on ListDensityPlot

Posted 10 months ago

I've got the following code:

data = Import["~/data.csv", {"Data", All, {1, 2, 3, 7}}];
dt = Table[{
    Quantity[
     UnixTime[FromDateString[data[[i, 1]] <> " " <> data[[i, 2]]]], 
     "Seconds"],
    Quantity[data[[i, 3]], "Hertz"],
    data[[i, 4]]
    }, {i, Length[data]}
   ];
ListDensityPlot[dt, ImageSize -> Large]

...which produces the following chart:

enter image description here

Here's the problem: I would like to format the Y axis to not use scientific notation, and the X axis to use a date/time string based on the value (I had to use UnixTime on this data set to convert the date/time to an integer because keeping it as a Date object would result in a blank graph).

(In case you're wondering, this is processing the output of rtl_power showing possible available signals between 24 MHz and 1.7 GHz on a Software-Defined Radio.)

POSTED BY: Steven Buehler
data = Import["~/data.csv", {"Data", All, {1, 2, 3, 7}}];
dt = Table[{
    Quantity[
     UnixTime[FromDateString[data[[i, 1]] <> " " <> data[[i, 2]]]], 
     "Seconds"],
    Quantity[data[[i, 3]], "Hertz"],
    data[[i, 4]]
    }, {i, Length[data]}
   ];

(* Define custom tick functions *)
xTicks = Charting`ScaledTicks[{Identity, 
     QuantityMagnitude[Quantity[#, "Seconds"]] &}];
yTicks = Charting`ScaledTicks[{QuantityMagnitude, Identity}];

ListDensityPlot[dt, ImageSize -> Large, 
 FrameTicks -> {{yTicks, None}, {xTicks, None}}, 
 FrameLabel -> {"Frequency", "Time"}, 
 LabelStyle -> Directive[FontSize -> 12], 
 PlotLabel -> "Density Plot of RTL Power Data"]

In this code:

  1. xTicks and yTicks are custom tick functions that format the ticks on the X and Y axes, respectively.
  2. ChartingScaledTicks` is used to create custom ticks that handle the conversion between Unix
  3. timestamps and date strings and between Hertz and numerical values.
  4. FrameTicks option is used to specify the custom tick functions for the X and Y axes.
  5. FrameLabel is used to add labels to the axes.
  6. LabelStyle is used to set the font size for the axis labels.
  7. PlotLabel is used to add a title to the plot.

This configuration should format the X and Y axes according to your requirements. Adjust the LabelStyle and other formatting options as needed to match your desired visual style. I hope that helps you

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract