Message Boards Message Boards

0
|
10031 Views
|
6 Replies
|
7 Total Likes
View groups...
Share
Share this post:

How to plot a dual-axis chart

I need to plot the data in a dual-axis chart. Are there any examples or instructions? How do the axis scales and labels place on the left and right?

a = {100, 200, 300, 400, 500};
b = {1, 2, 3, 4, 5};
ListPlot[{a, b}]
POSTED BY: Tsai Ming-Chou
6 Replies

I never knew there was this resource~~~~ Thank you very much.

POSTED BY: Tsai Ming-Chou
Posted 4 years ago
a = {100, 200, 300, 400, 500};
b = {1, 2, 3, 4, 5}; 

ListPlot[{a, b}, Frame -> True, FrameTicks -> Automatic, 
  GridLines -> Automatic, PlotStyle -> PointSize@Large]

enter image description here

POSTED BY: Hans Milton
Posted 4 years ago

Hi Tsai,

It is unfortunate that WL has no built-in way to do this as far as I know. Here is one workaround.

plot1 = ListPlot[a,
   ImageSize -> 400,
   ImagePadding -> 40,
   PlotStyle -> ColorData[97][1],
   Frame -> {True, True, True, False},
   FrameStyle -> {Automatic, ColorData[97][1], Automatic, Automatic},
   FrameLabel -> {{"Plot a", None}, {None, None}}];

plot2 = ListPlot[b,
   ImageSize -> 400,
   ImagePadding -> 40,
   PlotRange -> {0, 10},
   PlotStyle -> ColorData[97][2],
   Frame -> {False, False, False, True},
   FrameStyle -> {Automatic, Automatic, Automatic, ColorData[97][2]},
   FrameTicks -> {{False, All}, {False, False}},
   FrameLabel -> {{None, "Plot b"}, {None, None}}];

Overlay[{plot1, plot2}]

enter image description here

POSTED BY: Rohit Namjoshi

Thank you very much for your help !

I hope that there will be built-in functions for the next update.

POSTED BY: Tsai Ming-Chou
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